2012-05-09

CODE - 用 java 發 get 的 http request

...
String getUrl = "http://xx.xx/test.php?sn=xx&path=xx";
URL url = new URL(getUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"));
loggerHelper.log("Contents of get request");
// 取得 return 值
String lines;
while ((lines = reader.readLine()) != null){
    loggerHelper.log("lines: "+lines);
}
reader.close();
connection.disconnect();
...

cf :
http://www.jiucool.com/java-sending-http-requests-get-and-post-method-request/
http://www.exampledepot.com/egs/java.net/post.html

沒有留言:

張貼留言