invoke google api demo

package request;

import java.io.BufferedReader;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLEncoder;

public class Main {
public static void main(String[] args) throws UnsupportedEncodingException {
String encoding = System.getProperty("file.encoding");
System.out.println(encoding);
String encoding1 = URLEncoder.encode("林", "utf-8");

System.out.println(encoding1);
try {
URL my_url = new URL(
// "http://127.0.0.1:4664/search?q=%E5%BA%84%E6%B0%B8%E5%94%A4&flags=68&num=10&s=t4VEGJVSnbZ9Mf8Ruz6SGqPcTYA&format=xml");
// "http://127.0.0.1:4664/search&s=XZAXASVZUPL4rIYhwEiuY-PCwfE?q=file&num=10&format=xml");
"http://127.0.0.1:4664/search&s=XZAXASVZUPL4rIYhwEiuY-PCwfE?q="+encoding1+"&num=10&format=xml");
InputStreamReader input = new InputStreamReader(my_url.openStream(),"UTF-8");
BufferedReader br = new BufferedReader(input);


String strTemp = "";
while (null != (strTemp = br.readLine())) {
System.out.println(strTemp);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章