httpClient を作成していて、特定のヘッダーを HttpGet リクエストに追加したい
現在のコードは次のリクエストを生成します。
GET /folder/index.html HTTP/1.0
ホスト: localhost:4444
接続: キープアライブ
ユーザーエージェント: Apache-HttpClient/4.2.1 (java 1.5)
私が望むのは、その request に別のヘッダー (If-Modified-Since) を追加することです。
どうすればいいですか?
ありがとうございました :)
public String httpGet(String s) {
String url = s;
StringBuilder body = new StringBuilder();
httpclient = new DefaultHttpClient(); // create new httpClient
HttpGet httpGet = new HttpGet(url); // create new httpGet object
try {
response = httpclient.execute(httpGet); // execute httpGet
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == HttpStatus.SC_OK) {
// System.out.println(statusLine);
body.append(statusLine + "\n");
HttpEntity e = response.getEntity();
String entity = EntityUtils.toString(e);
body.append(entity);
} else {
body.append(statusLine + "\n");
// System.out.println(statusLine);
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
httpGet.releaseConnection(); // stop connection
}
return body.toString(); // return the String
}