论坛首页 Java企业应用论坛

HttpClient POST请求

浏览 6377 次
精华帖 (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;
	}
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics