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. element+Vue el-form组件进行查询时,当输入框仅有一项时,回车自动提交表单,浏览器会刷新页面

    vue的写法就是el-form上添加阻止默认事件 @submit.native.prevent <el-form ref="queryForm" label-width=&q ...

  2. 挂上burpsuite代理之后显示505 HTTP Version Not Supported 解决方法

    505 HTTP Version Not Supported  什么意思呢? HTTP505状态码代表的意思是 服务器不支持的HTTP版本,即 HTTP 505 HTTP Version Not Su ...

  3. java猜数小游戏

    问题: 程序自动生成一个1~100之间的随机数字,使用程序猜出这个数字是多少: Random可以随机生成一个随机数 使用方法: 导包 创建对象 Random r = new Random(); //只 ...

  4. 判断python socket服务端有没有关闭的方法

    通过 getattr(socket, '_closed') 的返回值可以判断服务端的运行状态. True 是关闭状态,False 是运行中. import socket ip = 'localhost ...

  5. 使用vue渲染大量数据时应该怎么优化?

    Object.freeze 适合一些 big data的业务场景.尤其是做管理后台的时候,经常会有一些超大数据量的 table,或者一个含有 n 多数据的图表,这种数据量很大的东西使用起来最明显的感受 ...

  6. JQery easyUI 滚动分页

    var s1 = new Date().getTime();     $(document).ready(function(){        var flag = true;        //鼠标 ...

  7. Generamba构建模板,让开发变得更高效

    Generamba Generamba:是为使用 Xcode 而设计的代码生成器.它主要设计用于生成 VIPER 模块,但很容易自定义模板以生成任何其他模板(在 Objective-C 和 Swift ...

  8. oracle 索引操作

    1 查询表中所有的索引 -- 固定写法"tb_user"(注意大小写)为表名 select * from user_indexes where table_name='tb_use ...

  9. 尚硅谷大数据技术之Kettle软件介绍与使用方法

    ETL(Extract-Transform-Load的缩写,即数据抽取.转换.装载的过程),对于企业或行业应用来说,我们经常会遇到各种数据的处理,转换,迁移,所以了解并掌握一种ETL工具的使用,必不可 ...

  10. java使用apache-commons-lang3生成随机字符串(可自定义规则)

    在日常开发中,我们经常会遇到生成随机字符串的需求.可能是大小写字母+数字,也可能是其他各种字符.作为一个常用功能,我们完全没必要自己实现,有很多优质的类库已经做的很完善了.本文介绍的就是apache- ...