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. 向mysql插入数据报错 pymysql.err.DataError: (1406, "Data too long for column 'class' at row 1") 解决方案

    这个问题一开始更换数据类型或者数据类型的大小,发现还是不行.后面通过网上查询了一条神奇的sql语句分分钟钟的解决了 问题原因明明是: 字段的长度不够存放数据 解决方案: 在mysql命令行输入如下:S ...

  2. Git 知识

    1.git merge .git cherry-pick.git rebase 可以看出merge结果能够体现出时间线,但是rebase会打乱时间线. 而rebase看起来简洁,但是merge看起来不 ...

  3. 2022-04-28内部群每日三题-清辉PMP

    1.为了降低项目的质量成本(COQ)并增加验收产品的几率,需要进行质量审计.质量审计需要什么? A.质量管理计划和质量测量指标 B.过程分析 C.质量管理计划和质量核对单 D.过程决策程序平图(PDP ...

  4. appium:报错Message: Message: Parameters were incorrect. We wanted {"required":["value"]}

    python版本3.7.4,selenium版本4.0.0,Appium-Python-Client版本2.0.0,报错见标题 别人给出的建议:https://blog.csdn.net/liangs ...

  5. beego框架中的注解路由不生效的问题

    在测试中发现 使用注解路由的话 项目需要在gopath路径下的src下才可以 并且配置文件的 runmode = dev 然后执行bee run 在路由文件夹里才会生成commentRouter文件 ...

  6. elementui树状结构添加右键点击事件

    <el-tree :highlight-current="highlight" :data="folderList" :props="defau ...

  7. nginx通过参数代理到其他站点

    http { include mime.types; default_type application/octet-stream; resolver 8.8.8.8; ##Nginx0.6.18以后的 ...

  8. 数位dp( tzoj6061:Bomb-求49个数;tzoj1427: 不要62)

    6061:http://www.tzcoder.cn/acmhome/problemdetail.do?method=showdetail&id=6061 dfs记忆化搜索 #include& ...

  9. [iOS] 随手记录 IDFA 的一些相关内容

    IDFA  IDFA,广告标识符,类似于这一台设备的唯一性标识符,一般提供给第三方去做一些广告的关联. 但如果用户完全 重置系统,或者 "还原位置与隐私" 这个广告标示符会重新生成 ...

  10. uniapp打包app出现HTML5+ Runtime

    在manifest.json->源码视图的 "app-plus"下面添加: "app-plus" : { "compatible" : ...