java调用百度api生成短链接,跪求java代码 , 不要复制网上的,要自己亲测实际能运行的!谢谢package com.zhidao.www;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class TestShort {
public static void main(String[] args) {
// TODO Auto-generated method stub
String httpUrl = "";
String httpArg = "url_long=http%3A%2F%2Fapistore.baidu.com%2Fastore%2Fshopready%2F1973.html";
String jsonResult = request(httpUrl, httpArg);
System.out.println(jsonResult);
}
/**
* @param urlAll
*:请求接口
* @param httpArg
*:参数
* @return 返回结果
*/
public static String request(String httpUrl, String httpArg) {
BufferedReader reader = null;
String result = null;
StringBuffer sbf = new StringBuffer();
httpUrl = httpUrl + "?" + httpArg;
try {
URL url = new URL(httpUrl);
HttpURLConnection connection = (HttpURLConnection) url
.openConnection();
connection.setRequestMethod("GET");
// 填入apikey到HTTP header
connection.setRequestProperty("apikey","自己的apikey");
connection.connect();
InputStream is = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
String strRead = null;
while ((strRead = reader.readLine()) != null) {
sbf.append(strRead);
sbf.append("\r\n");
}
reader.close();
result = sbf.toString();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}
这个可以用 不过要自己申请下api key 得到的字符串也要自己解析
用java求最短路径问题,求源程序import java.util.Vector;
public class Link {
private Vector link = new Vector();
// private Link next = null;
public Link() {
}
public boolean addNode(Node setNode){//增加一个节点
setNode = checkNode(setNode);
if(setNode != null){
this.link.addElement((Node)setNode);
return true;
}
return false;
}
public void delNode(Node setNode){ //删除一个节点
if(!this.link.isEmpty()){
for(int i=0;ithis.link.size(); i++)
{
if(setNode.getPos() == ((Node)this.link.elementAt(i)).getPos()){
this.link.remove(i);
//System.out.println("asdfasdfas:"+this.link.size());
break;
}
}
}
}
public Node checkNode(Node setNode){//判断节点是否在链表里面并取得两者的最佳值
if(!this.link.isEmpty()setNode!=null){
for(int i=0;ithis.link.size(); i++)
{
if(setNode.getPos() == ((Node)this.link.elementAt(i)).getPos()){
if(setNode.getStep()((Node)this.link.elementAt(i)).getStep()){
setNode = (Node)this.link.elementAt(i);
this.link.remove(i);
}
else
return null;
break;
}
}
}
return setNode;
}
public boolean isEmpty(){
return this.link.isEmpty();
}
public Node getBestNode(){ //得到最好的节点
Node tmpNode = null;
if(!this.link.isEmpty()){
tmpNode = (Node)this.link.elementAt(0);
//System.out.println("tmpNodeStep:"+tmpNode.getStep());
//System.out.print("OpenNode(pos,step):");
for(int i=1;ithis.link.size(); i++)
{
//System.out.print("("+((Node)this.link.elementAt(i)).getPos()+","+((Node)this.link.elementAt(i)).getStep()+")");
if(tmpNode.getJudgeNum() = ((Node)this.link.elementAt(i)).getJudgeNum()){
tmpNode = (Node)this.link.elementAt(i);
}
}
}
return tmpNode;
}
}
public class FindBestPath {
private char[][] map = null;//地图
private int maxX,maxY;//最大的地图边界大小
推荐阅读
- 如何写出优质新媒体的标题,新媒体写作标题如何吸引人
- 石器大冒险无限钻石游戏,石器冒险破解版下载
- linux如何命令去录音,linux 音频
- 代码合规检查java 代码合规检查工具 开源
- 品牌网店如何引流,网店引流方式
- 日本冒险解谜恐怖游戏,日本冒险解谜恐怖游戏叫什么
- jquery页面延时加载,jquery设置延时动画
- java写抢购的代码 java能写抢购软件吗
- 怎么用360卫士清理NET文件的简单介绍