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. cat /dev/null > file后,ls查看文件大小未减小,du查看变为0

    一句话总结: 其他程序正在使用command > file写入文件:将command程序kill后使用command >> file写入文件,即可在command写入file时,用c ...

  2. Java使用Calendar获取月最大天数

    Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar ...

  3. jmeter组件

    1.进程:一个正在执行的程序就对应一个进程 线程:进程中的执行线索(一个进程有多个执行线索) 线程组:按照线程性质对线程进行分组 2.并发执行:多个线程同时执行 特点:执行结束的顺序和线程的启动顺序不 ...

  4. 浅写java环境配置

    我对于Java环境配置的理解: 下载JDK ==>安装JDK ==>在电脑的系统中添加JDK中所包含的Java环境 ==>重启(主要是给系统监测到环境,非必要,但是建议)==> ...

  5. AFNI 教程 步骤5:统计和建模

    第一部分 时间序列 用AFNI打开fMRI数据, Graph按钮可以打开信号界面,中心的信号是该像素的信号随着时间的变化图,m 可以显示更少的体素,M可以显示更多的体素.V 可以浏览整个图像,+ 可以 ...

  6. beanshell 响应数据的解析与变量的保存

    获取响应的数据 response = prev.getResponseDataAsString() //prev.getResponseDataAsString是Jmeter提供的方法,可以调取上次请 ...

  7. Vue: 单页面应用如何保持登录状态

    这篇文章写的还可以 https://www.xiabingbao.com/post/vue/vue-keep-logininfo.html

  8. Linux 第五节(特殊权限,隐藏权限,SU,SUDO,FHS文件系统层次化标准)

    特殊权限 SUID  执行者临时获取命令的所有权限(对程序进行设置) SGID  目录内新文件所有组,继承原有目录所有组的名称 SBID  粘滞位,保护位 chmod +权限  文件 chmod   ...

  9. 剑指 Offer II Trie前缀树

    初始化 数组初始化在class外的话 要memset 在主函数里面memset 在class内不用 062. 实现前缀树 class Trie { public: /** Initialize you ...

  10. PyTorch Geometric(pyg)学习

    参考2个链接: 第十六课.Pytorch-geometric入门(一)_tzc_fly的博客-CSDN博客_pytorch-geometric 第十七课.Pytorch-geometric入门(二)_ ...