Java/HttpComponents
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
// 下階層用テンプレート
#topicpath
----
//ここにコンテンツを記述します。
[[HttpComponents>http://hc.apache.org/]]はApacheが提供す...
**ダウンロード [#k8d8673d]
http://hc.apache.org/downloads.cgi
より
-httpcore-4.0.jar
-httpclient-4.0-beta2.jar
をダウンロードします。上記ライブラリはまた下記のCommonsの...
-commons-logging-1.1.1.jar
をダウンロードします。
**サンプル [#v760fcc2]
Googleの[[Google AJAX Search API>http://code.google.com/i...
import java.io.IOException;
import java.net.URLEncoder;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
public class HTTPMain {
public static void main(String[] args) throws ClientPr...
IOException {
String input = URLEncoder.encode("きのさいと", "UTF-...
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(
"http://ajax.googleapis.com/ajax/services/search...
+ input);
System.out.println("executing request " + httpget.ge...
// Create a response handler
ResponseHandler<String> responseHandler = new BasicR...
String responseBody = httpclient.execute(httpget, re...
System.out.println(responseBody);
}
}
実行結果は以下の通り(色々整形してます)
executing request http://ajax.googleapis.com/ajax/servic...
q=%E3%81%8D%E3%81%AE%E3%81%95%E3%81%84%E3%81%A8
{"responseData":
{"results":[
{"GsearchResultClass":"GwebSearch",
"unescapedUrl":"http://www.masatom.in/pukiwiki/inde...
"url":"http://www.masatom.in/pukiwiki/index.php%3FF...
"visibleUrl":"www.masatom.in",
"cacheUrl":"http://www.google.com/search?q\u003dcac...
"title":"FrontPage - \u003cb\u003eきのさいと\u003c/...
"titleNoFormatting":"FrontPage - きのさいと",
"content":"ようこそ「\u003cb\u003eきのさいと\u003c/...
はMasatomi KINOの備忘録として立ち上げた ...
{"GsearchResultClass":"GwebSearch",
"unescapedUrl":"http://www.masatom.in/pukiwiki/inde...
%A5%D7%A5%E9%A5%B0%A5%A4%A5%F3%B3%AB%C8%AF%A4%C...
"url":"http://www.masatom.in/pukiwiki/index.php%3FE...
%25A5%25D7%25A5%25E9%25A5%25B0%25A5%25A4%25A5%2...
C8%25AF%25A4%25CETIPS%25BD%25B8",
"visibleUrl":"www.masatom.in",
"cacheUrl":"http://www.google.com/search?q\u003dcac...
"title":"Eclipse/プラグイン開発のTIPS集 - \u003cb\u...
"titleNoFormatting":"Eclipse/プラグイン開発のTIPS集...
"content":"自体がこのプラグインのクラスローダでロー...
プラグ イン側のクラスが見えないっ。。}
],
"cursor":
{"pages":[
{"start":"0","label":1},
{"start":"4","label":2},
{"start":"8","label":3},
{"start":"12","label":4},
{"start":"16","label":5},
{"start":"20","label":6},
{"start":"24","label":7},
{"start":"28","label":8}
],
"estimatedResultCount":"560000",
"currentPageIndex":0,
"moreResultsUrl":"http://www.google.com/search?oe\...
\u0026source\u003duds\u0026start...
\u0026q\u003d%E3%81%8D%E3%81%AE%E3%81%95%...
}
},
"responseDetails": null,
"responseStatus": 200
}
JSON形式のStringが取得できました。
**関連リンク [#p93d450f]
-[[Google AJAX Search API>http://code.google.com/intl/ja/...
-[[HttpCore Tutorial>http://hc.apache.org/httpcomponents-...
----
この記事は
#vote(おもしろかった,そうでもない)
#comment
#topicpath
SIZE(10){現在のアクセス:&counter;}
終了行:
// 下階層用テンプレート
#topicpath
----
//ここにコンテンツを記述します。
[[HttpComponents>http://hc.apache.org/]]はApacheが提供す...
**ダウンロード [#k8d8673d]
http://hc.apache.org/downloads.cgi
より
-httpcore-4.0.jar
-httpclient-4.0-beta2.jar
をダウンロードします。上記ライブラリはまた下記のCommonsの...
-commons-logging-1.1.1.jar
をダウンロードします。
**サンプル [#v760fcc2]
Googleの[[Google AJAX Search API>http://code.google.com/i...
import java.io.IOException;
import java.net.URLEncoder;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
public class HTTPMain {
public static void main(String[] args) throws ClientPr...
IOException {
String input = URLEncoder.encode("きのさいと", "UTF-...
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(
"http://ajax.googleapis.com/ajax/services/search...
+ input);
System.out.println("executing request " + httpget.ge...
// Create a response handler
ResponseHandler<String> responseHandler = new BasicR...
String responseBody = httpclient.execute(httpget, re...
System.out.println(responseBody);
}
}
実行結果は以下の通り(色々整形してます)
executing request http://ajax.googleapis.com/ajax/servic...
q=%E3%81%8D%E3%81%AE%E3%81%95%E3%81%84%E3%81%A8
{"responseData":
{"results":[
{"GsearchResultClass":"GwebSearch",
"unescapedUrl":"http://www.masatom.in/pukiwiki/inde...
"url":"http://www.masatom.in/pukiwiki/index.php%3FF...
"visibleUrl":"www.masatom.in",
"cacheUrl":"http://www.google.com/search?q\u003dcac...
"title":"FrontPage - \u003cb\u003eきのさいと\u003c/...
"titleNoFormatting":"FrontPage - きのさいと",
"content":"ようこそ「\u003cb\u003eきのさいと\u003c/...
はMasatomi KINOの備忘録として立ち上げた ...
{"GsearchResultClass":"GwebSearch",
"unescapedUrl":"http://www.masatom.in/pukiwiki/inde...
%A5%D7%A5%E9%A5%B0%A5%A4%A5%F3%B3%AB%C8%AF%A4%C...
"url":"http://www.masatom.in/pukiwiki/index.php%3FE...
%25A5%25D7%25A5%25E9%25A5%25B0%25A5%25A4%25A5%2...
C8%25AF%25A4%25CETIPS%25BD%25B8",
"visibleUrl":"www.masatom.in",
"cacheUrl":"http://www.google.com/search?q\u003dcac...
"title":"Eclipse/プラグイン開発のTIPS集 - \u003cb\u...
"titleNoFormatting":"Eclipse/プラグイン開発のTIPS集...
"content":"自体がこのプラグインのクラスローダでロー...
プラグ イン側のクラスが見えないっ。。}
],
"cursor":
{"pages":[
{"start":"0","label":1},
{"start":"4","label":2},
{"start":"8","label":3},
{"start":"12","label":4},
{"start":"16","label":5},
{"start":"20","label":6},
{"start":"24","label":7},
{"start":"28","label":8}
],
"estimatedResultCount":"560000",
"currentPageIndex":0,
"moreResultsUrl":"http://www.google.com/search?oe\...
\u0026source\u003duds\u0026start...
\u0026q\u003d%E3%81%8D%E3%81%AE%E3%81%95%...
}
},
"responseDetails": null,
"responseStatus": 200
}
JSON形式のStringが取得できました。
**関連リンク [#p93d450f]
-[[Google AJAX Search API>http://code.google.com/intl/ja/...
-[[HttpCore Tutorial>http://hc.apache.org/httpcomponents-...
----
この記事は
#vote(おもしろかった,そうでもない)
#comment
#topicpath
SIZE(10){現在のアクセス:&counter;}
ページ名: