我正在尝试使用原始数据发送http post请求。
原始数据格式如下所述
{“value”:“01712211022”,“password”:“test”}。如何使用请求URL添加原始数据?
任何建议都将不胜感激。
答案 0 :(得分:2)
见这里:http://www.androidsnippets.com/executing-a-http-post-request-with-httpclient
或使用以下示例:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
try {
httppost.setEntity(new ByteArrayEntity(data));
HttpResponse result = httpclient.execute(httppost);
HttpEntity resultEntity = result.getEntity();
} catch (ClientProtocolException e) {
/**/
} catch (IOException e) {
/**/
}
并且不要忘记将这些行添加到清单:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />