開発メモ/Android/HTTP通信
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
*HTTP通信 [#w0eb23c7]
AndroidでHTTP通信する方法。~
こんな感じ。
#codeprettify{{
private static CookieStore store = null;
・・・
DefaultHttpClient client = new DefaultHttpClient();
HttpParams params = client.getParams();
HttpConnectionParams.setConnectionTimeout(params, 5000);
HttpConnectionParams.setSoTimeout(params, 10000);
HttpGet method = new HttpGet(url);
// クッキーの設定。クッキーの内容を引き継ぎたい場合に、...
// 時のCookieStoreのインスタンスを再利用する。
client.setCookieStore(store);
method.setHeader( "Connection", "Keep-Alive" );
HttpResponse response = null;
String res = null;
try {
response = client.execute( method );
// 次の接続時もCookieを使うために退避
store = client.getCookieStore();
int status = response.getStatusLine().getStatusCode();
if ( status == HttpStatus.SC_OK ){
res = EntityUtils.toString( response.getEntity(), "...
}
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
}}
参考にしたサイトのURLがわからなくなってしまった・・・~
終了行:
*HTTP通信 [#w0eb23c7]
AndroidでHTTP通信する方法。~
こんな感じ。
#codeprettify{{
private static CookieStore store = null;
・・・
DefaultHttpClient client = new DefaultHttpClient();
HttpParams params = client.getParams();
HttpConnectionParams.setConnectionTimeout(params, 5000);
HttpConnectionParams.setSoTimeout(params, 10000);
HttpGet method = new HttpGet(url);
// クッキーの設定。クッキーの内容を引き継ぎたい場合に、...
// 時のCookieStoreのインスタンスを再利用する。
client.setCookieStore(store);
method.setHeader( "Connection", "Keep-Alive" );
HttpResponse response = null;
String res = null;
try {
response = client.execute( method );
// 次の接続時もCookieを使うために退避
store = client.getCookieStore();
int status = response.getStatusLine().getStatusCode();
if ( status == HttpStatus.SC_OK ){
res = EntityUtils.toString( response.getEntity(), "...
}
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
}}
参考にしたサイトのURLがわからなくなってしまった・・・~
ページ名: