浏览 6379 次
锁定老帖子 主题:HttpClient POST请求
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (2)
|
|
---|---|
作者 | 正文 |
发表时间:2009-11-06
public void test(PayInfoDetailImpl payInfoDetailImpl) throws IOException { String url = xxxL; String host = xxx; String https = xxx; HttpClient httpClient = new HttpClient(); httpClient.getHostConfiguration().setHost(host, 80, https); HttpMethod method = postMethod(url, payInfoDetailImpl); httpClient.executeMethod(method); String response = method.getResponseBodyAsString(); System.out.println(response); } /** * post请求方法 * * @param url * @return * @throws IOException */ private HttpMethod postMethod(String url, PayInfoDetailImpl payInfoDetailImpl) throws IOException { PayInfoImpl payInfoImpl = new PayInfoImpl(); System.out.println("返回地址: " + payInfoImpl.getPageUrl()); PostMethod post = new PostMethod(url); post.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=gb2312"); String orderTime = new java.text.SimpleDateFormat("yyyyMMddHHmmss") .format(new java.util.Date()); NameValuePair[] param = { new NameValuePair("xxxx", xxx), new NameValuePair("xxx",xxxx), }; post.setRequestBody(param); post.releaseConnection(); return post; } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |