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. js开发环境如何解决跨域问题

    问题 npm start之后,自己会启动一个端口,比如3000,调用后端服务(比如localhsot:3006/service/list)就会出现跨域,那怎么弄呢? 方式一: webpack设置pro ...

  2. python 操作配置文件(configparser模块)

    用于生成和修改常见配置文档,当前模块的名称在 python 3.x 版本中变更为 configparser 配置文件信息: [DEFAULT] ServerAliveInterval = 45 Com ...

  3. plugin的原理

    plugin插件的原理 扩展webpack, 加入自定义的构建行为 webpack内部的钩子 hooks tap: 可以注册同步钩子和异步钩子 tapAsync: 回调方式注册异步钩子 tapProm ...

  4. CH582m模拟JoyStick使用USB与电脑通信

    目录 本程序改编自沁恒官网2022年1月更新的CH583EVT中的CompoundDev例程.这里只贴了main.c中的程序.能够实现:①直接接电脑,在设备管理器中能够查到被电脑识别为HID-comp ...

  5. CH32F103C8T6调试口Disable后的修复办法

    1.问题描述 因为软件编程,将CH32F103的 debug disable了,无法通过仿真器下载程序. 2. 修复 2.1 解决思路 利用厂家给的串口ISP进行下载(HUSB或者COM) 2.2 硬 ...

  6. [Swift] SwiftUI布局的一些写法基础(用Swift构造UI布局)

    这个文档是在你 完全熟悉 Objective-C 上用代码构造UI的前提下写的 官方教程:https://developer.apple.com/tutorials/swiftui/creating- ...

  7. Markdown的在线使用

    欢迎使用 Markdown在线编辑器 MdEditor Markdown是一种轻量级的「标记语言」 Markdown是一种可以使用普通文本编辑器编写的标记语言,通过简单的标记语法,它可以使普通文本内容 ...

  8. 2022-03-02 关于 react-native 如何使用 react-native-image-crop-picker

    前言:react-native项目(下称rn)中需要用到图片裁剪.从相册取照片以及调用手机相机,主要用到这个插件react-native-image-crop-picker. 安装: yarn add ...

  9. john破解linux用户密码

    John是kali-linux自带的密码破解工具,支持密码本破解.Linux的系统账户在/etc/passwd中,密码存于/etc/shadow中. 以下操作为例: (1)创建一个账户,

  10. Java06 面向对象

    一 什么是面向对象 面向对象编程(Object-Oriented Programming,OOP) 面向对象编程的本质就是:以类的方式组织代码,以对象组织(封装)数据. 三大特性: 封装 继承 多态 ...