项目用由于需要用到post来提交数据,主要是因为自己原先用get时字符串中带有‘’+‘’号的会被转义成空的,所以只能改成post方式进行提交了,整个项目没见有post提交方式,
所以网上也找了许多,不过现在好了。
用post进行提交数据:
String hr_token = mSP.getString(CommonData.HR_TOKEN, "");//该token为数据库进行获取 String strUrl = "http://" + CommonData.HRServerIP+ CommonData.HeartBeatCheck + "?terminalID=" + mDeviceID;//mDeviceID为设备ID也是由其它进行传进行 String strHttps = HttpSend.post(strUrl,hr_token);//这里主要是调用post进行提交token
下面为调用的post方法:
public static String post(String Url ,String token) throws Exception { String path = Url; HttpClient client = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(path); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("Token", token)); httpPost.setEntity(new UrlEncodedFormEntity(params, "utf-8")); HttpResponse response = client.execute(httpPost); if (200 == response.getStatusLine().getStatusCode()) { // return response.getEntity().getContent(); } return response.getStatusLine().getStatusCode()+""; }
原文链接:https://blog.csdn.net/llixiangjian/article/details/77494407
本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。
还没有人抢沙发呢~