HttpClient 3.1 发送 post请求

HttpClient 3.1

HttpClient httpClient = new HttpClient();
//url是请求的url
PostMethod postMethod = new PostMethod(url);
//提交的请求参数。请求参数不要包含在url里,这样请求参数长度不受url长度限制。
postMethod.setParameter("requestdata",data);
// 返回的状态码 
int statusCode = httpClient.executeMethod(postMethod);
// 获取响应数据,二进制
byte[] responseBody = postMethod.getResponseBody();

// 获取响应数据流
InputStream in = postMethod.getResponseBodyAsStream();

//释放连接
postMethod.releaseConnection();

//设置重试
postMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
                new DefaultHttpMethodRetryHandler(3, false));


你可能感兴趣的:(httpclient)