一个http请求二次请求才能获取到数据,为什么,url的问题?

 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");
    	Listparams=new ArrayList();
    	
    	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);
    		}
    	}



你可能感兴趣的:(java)