【发布时间】:2012-10-12 17:48:14
【问题描述】:
我需要从移动 android 应用程序向服务器端应用程序发送 http POST 请求。 此请求需要在正文中包含 json 消息和一些键值参数。 我正在尝试编写此方法:
public static String makePostRequest(String url, String body, BasicHttpParams params) throws ClientProtocolException, IOException {
Logger.i(HttpClientAndroid.class, "Make post request");
HttpPost httpPost = new HttpPost(url);
StringEntity entity = new StringEntity(body);
httpPost.setParams(params);
httpPost.setEntity(entity);
HttpResponse response = getHttpClient().execute(httpPost);
return handleResponse(response);
}
这里我通过setParams方法设置参数来请求并通过setEntity设置json body。 但这行不通。 有人可以帮帮我吗?
【问题讨论】: