private String backAllUserInfo(String uid) throws IOException {
//this.setInterfaceurl("/idm/jsoninterface/userManager/getUserByUid.do");
this.setInterfaceurl("/api/user/get/userinfobyloginname.do?loginName="+uid);//如果是post去掉url后参数放到下面NameValuePair里面传递
String timestamp=String.valueOf(System.currentTimeMillis());
String response = "";
GetMethod postMethod = new GetMethod(getInterfaceURL());//如果是post请求则GetMethod换成PostMethod
HttpMethodParams parms = new HttpMethodParams();
parms.setContentCharset("UTF-8"); // 在header中放入用户名和密码
//NameValuePair[] data = { new NameValuePair("loginName",uid) }; //postMethod.setParams(parms);
//postMethod.setRequestHeader("loginName", uid);
//postMethod.setRequestHeader("password",
//"A722C63DB8EC8625AF6CF71CB8C2D939");
postMethod.setRequestHeader("timestamp", timestamp);
postMethod.setRequestHeader("token",getToken("D73CABDB3B5F085523C46D3CFAC3EB3B8BB9", "netgate_test",timestamp ));
postMethod.setRequestHeader("appid","netgate_test");
InputStream inputStream = null;
BufferedReader br =null;
try {
//postMethod.setRequestBody(data);
HttpClient client = new HttpClient(new HttpClientParams(),
new SimpleHttpConnectionManager(true));
//设置连接超时时时间
client.getHttpConnectionManager().getParams()
.setConnectionTimeout(10000);
//设置读取数据超时时时间
client.getHttpConnectionManager().getParams().setSoTimeout(10000);
// 设置连接时间
int status = client.executeMethod(postMethod);
if (status == HttpStatus.SC_OK) {
inputStream = postMethod.getResponseBodyAsStream();
br = new BufferedReader(new InputStreamReader(
inputStream, "UTF-8"));
StringBuffer stringBuffer = new StringBuffer();
String str = "";
while ((str = br.readLine()) != null) {
stringBuffer.append(str);
}
response = stringBuffer.toString();
} else {
response = "";
}
} catch (Exception e) {
super.setError(STATU_CONNERROR);
e.printStackTrace();
} finally {
try {
if (br != null) {
br.close();
}
if (inputStream != null) {
inputStream.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
}
// 释放连接
postMethod.releaseConnection();
}
return response;
}
    public String getInterfaceURL() {
Config config = Config.getInstance();
String ip = config.getValue("idm.ip");
String port = config.getValue("idm.port");
StringBuffer buffer = new StringBuffer();
buffer.append("http://");
buffer.append(ip);
buffer.append(":");
buffer.append(port);
buffer.append(this.getInterfaceurl());
return buffer.toString();
}

HttpClient psot和get请求的更多相关文章

  1. HttpClient (POST GET PUT)请求

    HttpClient (POST GET PUT)请求 package com.curender.web.server.http; import java.io.IOException; import ...

  2. HttpClient方式模拟http请求设置头

    关于HttpClient方式模拟http请求,请求头以及其他参数的设置. 本文就暂时不给栗子了,当作简版参考手册吧. 发送请求是设置请求头:header HttpClient httpClient = ...

  3. HttpClient发送get post请求和数据解析

    最近在跟app对接的时候有个业务是微信登录,在这里记录的不是如何一步步操作第三方的,因为是跟app对接,所以一部分代码不是由我写,我只负责处理数据,但是整个微信第三方的流程大致都差不多,app端说要传 ...

  4. HttpWebRequest 改为 HttpClient 踩坑记-请求头设置

    HttpWebRequest 改为 HttpClient 踩坑记-请求头设置 Intro 这两天改了一个项目,原来的项目是.net framework 项目,里面处理 HTTP 请求使用的是 WebR ...

  5. 使用HttpClient发送Get/Post请求 你get了吗?

    HttpClient 是Apache Jakarta Common 下的子项目,可以用来提供高效的.最新的.功能丰富的支持 HTTP 协议的客户端编程工具包,并且它支持 HTTP 协议最新的版本和建议 ...

  6. org.apache.httpcomponents httpclient 发起HTTP JSON请求

    1. pom.xml <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactI ...

  7. httpclient的几种请求URL的方式

    一.httpclient项目有两种使用方式.一种是commons项目,这一个就只更新到3.1版本了.现在挪到了HttpComponents子项目下了,这里重点讲解HttpComponents下面的ht ...

  8. HttpClient发起Http/Https请求工具类

    <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpcl ...

  9. HttpClient方式模拟http请求

    方式一:HttpClient import org.apache.commons.lang.exception.ExceptionUtils; import org.apache.http.*; im ...

  10. Android HttpClient GET或者POST请求基本使用方法(转)

    在Android开发中我们经常会用到网络连接功能与服务器进行数据的交互,为此Android的SDK提供了Apache的HttpClient来方便我们使用各种Http服务.这里只介绍如何使用HttpCl ...

随机推荐

  1. [JavaScript]对象数组 - 不完全整理

    对象数组中查询属性为某个值的对象,使用Array.find() const array1 = [5, 12, 8, 130, 44]; const found = array1.find(elemen ...

  2. 2022-05-07内部群每日三题-清辉PMP

    1.项目需要一位熟练的工程师来执行某个特定任务,但由于工作量大,该工程师不能参与这个项目.项目经理下一步应该怎么做? A.修改进度计划,以适应该资源 B.与职能经理协商该资源的参与 C.培训项目团队中 ...

  3. <input>输入框,限制输入的为正整数

    <input id="eventId" col="EventId" type="text" class="form-cont ...

  4. CTreeView和CTreeCtrl的使用方法(转)

    (一)树控制的主要功能 树控制和视(Tree Control&View)主要用来显示具有一定层次结构的数据项,如资源管理器中的磁盘目录等,以供用户在其中进行各种选择.树控制中的每个数据项包括数 ...

  5. C#-out和ref 参数修饰符

    参数修饰符: 无参数修饰符:如果一个参数没有任何参数修饰符修饰,那么认为它是值传递,意味着方法内部收到的是实参数据的副本 out:输出参数由方法内部进行赋值,(引用传递),如果方法内部没有给被out修 ...

  6. 文件监控利器-Jnotify

    监听的文件变化的方式有很多,但是比较完美的还是jNotify https://jnotify.sourceforge.net/ 对比一下监控方式的优缺点 方式 缺点 java原生watch 可能对文件 ...

  7. mybatis 数据搜索后参数显示乱码无法搜到

    今天写作业的时候遇到的小问题 问题说明:搜索订单名中含有"香皂"的订单,显示订单的一系列属性.在搜索后,调试框中显示的东西很奇怪,也没有查找到答案: 觉得是编码问题,所以调试了编码 ...

  8. popen函数和pyinstaller打包之 -w冲突

    启发文章:https://www.jb51.net/article/184731.htm 之前我也是用到了os.popen()这个函数 1.os.popen(self.excel_path)  括号里 ...

  9. NGINX一次电脑自己可以访问其它IP访问不了

    配制好NGINX 本地电脑curl http..... 正常访问...其它电脑不可以 第一想法防火墙 查一下  firewall-cmd --state not running 然后查下是不是服务开启 ...

  10. 记一次Mybatis-Plus动态分表DynamicTableNameInnerInterceptor里无法动态替换表名的坑

    首先上源码 protected String changeTable(String sql) { ExceptionUtils.throwMpe(null == tableNameHandler, & ...