我正在尝试发送带有原始数据的 http post 请求。
原始数据格式如下所述
{“值”:“01712211022”,“密码”:“测试”}。如何使用请求 URL 添加原始数据?
任何建议将不胜感激。
见这里: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" />