我正在创建httpClient,并且当我发送httpPost方法时,如何将一个主体附加到httpRequest?httpPost方法
public String httpPost(String URL, String BODY) {
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(URL);
try {
response = httpclient.execute(httpPost); // get response from executing client
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == HttpStatus.SC_OK) {
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 {
httpPost.releaseConnection();
}
return body.toString();
}
例如,字符串是
“< HTML> <头>标题< /报头> <体>我体</BODY>”
哪里该字符串附加到所述请求消息?
谢谢:)
setEntity方法仅需要实体...我想知道如何将字符串解析为实体.. – Ken