标签:
版本:4.1
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url); // httpPost.setHeader("Accept-Encoding", "gzip,deflate");//表示返回的数据是压缩的zip格式 String postParam = "";//请求的参数内容 List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("data", postParam)); httpPost.setEntity(new UrlEncodedFormEntity(nvps,"utf-8")); HttpResponse response = httpClient.execute(httpPost); HttpEntity entity = response.getEntity(); if (response.getStatusLine().getStatusCode() == 200) {if (entity.getContentEncoding().toString().equalsIgnoreCase("Content-Encoding: gzip")) { response.setEntity(new GzipDecompressingEntity(response.getEntity())); //对zip进行解压 entity = response.getEntity(); } String responseContent = EntityUtils.toString(entity); System.out.println("responseContent: \n" + responseContent); } }
HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); // httpPost.setHeader("Accept-Encoding", "gzip,deflate");//表示返回的数据是压缩的zip格式 String postParam = "";//请求的参数内容 StringEntity paramEntity = new StringEntity(postParam);//无参数名,只是参数内容 httpPost.setEntity(paramEntity); HttpResponse response = httpClient.execute(httpPost); HttpEntity entity = response.getEntity(); if (response.getStatusLine().getStatusCode() == 200) {if (entity.getContentEncoding().toString().equalsIgnoreCase("Content-Encoding: gzip")) { response.setEntity(new GzipDecompressingEntity(response.getEntity())); //对zip进行解压 entity = response.getEntity(); } String responseContent = EntityUtils.toString(entity); System.out.println("responseContent: \n" + responseContent); } }
httpclient post请求例子(无参数名与带参数名的例子)
标签:
原文地址:http://www.cnblogs.com/aisam/p/4704164.html