HttpClient请求地址并携带参数

废话不多,直接上代码!

 1     /**
 2      *
 3      * @param httpUrl
 4      * @param reqInfo
 5      * @return
 6      */
 7     public static StringBuffer sendPost(String httpUrl, RequestInfoDTO reqInfo) {
 8         try {
 9             logger.info("请求地址 --->" + httpUrl);
10             PostMethod postMethod = new PostMethod(httpUrl);
11             HttpClient httpClient = new HttpClient();
12             String requestJson = com.bocins.springcloud.util.JsonUtils.obj2Json(reqInfo);
13             logger.info("请求参数转json --->" + requestJson);
14             postMethod.setRequestEntity(new StringRequestEntity(requestJson, "text/xml", "GBK"));
15             httpClient.executeMethod(postMethod);
16             BufferedReader reader = null;
17             reader = new BufferedReader(new InputStreamReader(postMethod.getResponseBodyAsStream(),"UTF-8"));
18             String lines;
19             StringBuffer sb = new StringBuffer("");
20             while((lines = reader.readLine()) != null){
21                 lines = new String(lines.getBytes());
22                 sb.append(lines);
23             }
24             logger.info("服务调用返回结果 --->" + sb);
25             return sb;
26         }catch(Exception e){
27             logger.info("****************服务调用出错****************",e);
28         }
29         return null;
30     }

原文地址:https://www.cnblogs.com/lfyu/p/9268494.html

时间: 2024-08-30 17:28:36

HttpClient请求地址并携带参数的相关文章

js获取请求地址?后的参数和值

js获取请求地址?后的参数和值 //获取url中的参数 function getUrlParam(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象 //alert("window.location.search="+window.location.search); var r = window.locat

[技巧篇]11.JavaScript原生态如何获取浏览器请求地址中的参数

var getAccessParams = function(){ var i,ilen,strs,keyName,keyValue, params={}, path = window.location.pathname, url = window.location.href; if(url.indexOf("?")>-1){ var index=url.indexOf("?"); strs=url.substring(index+1); //console.

Springboot 3.需求携带参数的get请求

还是拿来上节讲的代码: package com.course.server; import org.springframework.web.bind.annotation.*; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.HashMap; import j

有道词典翻译(携带请求头和post参数请求)

一.静态爬取页面信息 body { background-color: #f4ede3 } .box { width: 600px } 有道翻译网址:http://fanyi.youdao.com/ 在翻译中输入python 找到接口和请求的方式 参数是From Data类型 需要把参数数据转换为字典, 复制粘贴后按住Ctrl + r ,然后 Headers 内容的长度是data携带参数的长度 代码实现 分析:红色圈住的,是会根据要翻译的内容变化而变化 运行结果: 代码: import requ

JAVA发送HttpClient请求及接收请求结果过程

下面为本人自己在工作中写业务代码的,并不是通用的,只供自己下次使用时能有个查找地,及正处在困扰中的程序员借鉴. 推荐好点博客给大家看看: http://blog.sina.com.cn/s/blog_75a8cfac01013aim.html http://blog.csdn.net/fireelement/article/details/2497136 http://www.2cto.com/kf/201206/136879.html http://284772894.iteye.com/bl

HTTPclient 4.2.2 传参数和文件流

package com.http; import java.io.File; import java.io.IOException; import java.io.UnsupportedEncodingException; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.client.C

springMVC get请求及其请求地址写法

今天,需要写一个接口,写完之后,测试的时候发线一直报404错误,不知道为什么报错.应该是get请求地址的问题,get请求有两个参数,改为一个参数的时候是好用的,可能那种方式不适合写两个参数的get请求吧. 方式一:get请求一个参数 @RequestMapping("/testPathVariable/{id}") public String testPathVariable(@PathVariable(value="id") Integer id){ System

通过HttpClient请求webService

由于服务端是用webService开发的,android要调用webService服务获取数据,这里采用的是通过HttpClient发送post请求,获取webService数据. 服务端使用的webService框架是axis2,请求数据之前,要封装一个xml格式,再通过post请求,获取服务端数据. 请求的xml格式如下所示: 1 <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"xmlns:

Java httpclient请求,解决乱码问题

public class HttpPostRequestUtil { public HttpPostRequestUtil() { } public static String post(String url, Map<String, String> maps) { // 第一步,创建HttpPost对象 HttpPost httpPost = new HttpPost(url); // 设置HTTP POST请求参数必须用NameValuePair对象 List<NameValuePa