一个http请求二次请求才能获取到数据,为什么,url的问题?
2016-12-05 13:36
751 查看
public static void t(String[] args) throws ClientProtocolException, IOException, InterruptedException{ HttpClient httpClient=new DefaultHttpClient(); HttpPost httpPost=new HttpPost("http://172.19.10.137:8601/bjt1deea3e3e7fb/js/data/user_info.json"); List<NameValuePair>params=new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("codeType","bno")); params.add(new BasicNameValuePair("userNumber","B23871039")); params.add(new BasicNameValuePair("business","data")); UrlEncodedFormEntity entity=new UrlEncodedFormEntity(params,"utf-8"); httpPost.setEntity(entity); HttpResponse httpResponse1 =httpClient.execute(httpPost); //释放 不知道为什么不释放一次取不到返回 httpPost.releaseConnection(); HttpResponse httpResponse =httpClient.execute(httpPost); if(httpResponse.getStatusLine().getStatusCode()==200){ //请求和响应都成功了 HttpEntity rentity=httpResponse.getEntity();//调用getEntity()方法获取到一个HttpEntity实例 String response=EntityUtils.toString(rentity,"utf-8");//用EntityUtils.toString()这个静态方法将HttpEntity转换成字符串,防止服务器返回的数据带有中文,所以在转换的时候将字符集指定成utf-8就可以了 System.out.println("-------------------------------------"); System.out.println(response); } }
相关文章推荐
- Web HttpServletRequest的getRequestURL方法获取不到https协议请求问题
- HttpURLConnection获取网络数据(实例:网路请求图片)
- IE浏览器中XMLHttpRequest对同一个URL只发送一个请求问题的解决。
- Java请求一个URL。获取网站返回的数据。
- 使用HttpURLConnection采用get方式请求数据-----乱码问题
- IE浏览器中XMLHttpRequest对同一个URL只发送一个请求问题的解决。
- java通过Http get post请求url获取数据
- 腾讯云图片鉴黄集成到C# SQL Server 怎么在分页获取数据的同时获取到总记录数 sqlserver 操作数据表语句模板 .NET MVC后台发送post请求 百度api查询多个地址的经纬度的问题 try{}里有一个 return 语句,那么紧跟在这个 try 后的 finally {}里的 code 会 不会被执行,什么时候被执行,在 return 前还是后? js获取某个日期
- 为什么返回的数据前面有callback? ashx/json.ashx?的后面加 callback=? 起什么作用 js url?callback=xxx xxx的介绍 ajax 跨域请求时url参数添加callback=?会实现跨域问题
- 第十二篇:Android GET请求获取网络数据以及POST数据(使用HttpURLConnection)
- Java请求一个URL。获取网站返回的数据。
- 使用HttpURLConnection发请求获取数据
- 解决httpurlconnection获取网页数据部分中文乱码问题
- 获取远程的字符串(请求一个URL, 返回这个请求页面的页面数据)
- Java请求一个URL,获取返回的数据
- 通过网卡获取http请求数据
- JS提交请求url中存在中文的问题的一个解决方案
- 关于从不同的URL获取JSON数据时Ext.data.Store反映迟缓问题的解决
- js获取url中请求数据
- GET、POST请求处理中文问题(用HttpURLConnection模拟发送请求)