HttpClient使用例子
2014-06-06 16:33
369 查看
HttpClient使用例子
(2011-09-21 14:51:38)转载▼
标签:
| 分类: JAVA |
String url = http://localhost:8080/ana/workFlowOaInterface.do?action=oaTask;
PostMethod postMethod = new PostMethod(url);
//设置参数编码为gbk
post.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"gbk");
//构造键值对参数
NameValuePair[] data = { new NameValuePair("processInstanceId", "230"), new NameValuePair("approveFlag", "1") };
// 把参数值放入postMethod中
postMethod.setRequestBody(data);
//执行
client.executeMethod(postMethod);
//读取内容
byte[] responseBody = postMethod.getResponseBody();
//处理内容
System.out.println(new String(responseBody));
System.out.println("getStatusLine:"+postMethod.getStatusLine());
System.out.println("~~~"+postMethod.getResponseBodyAsString());
System.out.println("statusCode:"+statusCode);
//打印结果页面
String response = new String(postMethod.getResponseBodyAsString().getBytes("utf-8"));
//打印返回的信息
System.out.println("response:"+response);
//释放连接
postMethod.releaseConnection();
如果传递的是中文参数,有可能会出现乱码,通过设置正确的参数编码来解决。
在被调用的接口方,直接通过request.getParameter的方式获取。
相关文章推荐
- android使用webview登录,获取session传递到httpclient小例子
- HttpClient使用例子
- HttpClient使用例子:读取CSDN的投票列表并正则解析
- HttpClient使用简单例子
- HttpClient读取页面的使用例子
- HttpClient读取页面的使用例子
- android使用webview登录,获取session传递到httpclient小例子
- HttpClient使用GET方式通过代理服务器读取页面的例子
- HttpClient 4使用方法的几个例子
- 一个HttpClient使用Windows认证请求WCF服务的例子
- HttpClient 4使用方法的几个例子
- HttpClient 4使用方法的几个例子(代理,StringEntity字符串数据,文件上传)(转载)
- HttpClient 4使用方法的几个例子
- httpclient 4.x使用入门例子
- HttpClient 4 使用POST方式提交普通表单数据的例子
- HttpClient 4使用方法的几个例子
- commons-httpclient.jar的使用2
- 使用JAVA发送HTTP请求(Http Request),返回HTTP响应(Http Response)内容,代码程序例子及原理说明
- HttpClient基本功能的使用
- [zz]HttpClient的基本使用