Http Client是个apache下的一个开源包,用于使用http协议访问服务的java代码编写。

Http Client的主要功能:

(1)实现了所有 HTTP 的方法(GET,POST,PUT,HEAD 等)
(2)支持自动转向
(3)支持 HTTPS 协议
(4)支持代理服务器等

使用Http Client需要的包:commons-httpclient.jar,commons-logging.jar,commons-codec-1.x.jar

Http Client使用(以Post方式为例)

HttpClient httpClient = new HttpClient();

// 访问主机IP

String host = “198.32.32.2”;

// 端口号

int port = 8081;

// 协议

String protocol = “http”;

httpClient.getHostConfiguration().setHost(host,port, protocol);

// 具体访问路径

String url = “”

HttpMethod method = new PostMethod(url);

// 参数

NameValuePair[] data = { new NameValuePair("id", "youUserName"), new NameValuePair("passwd", "yourPwd") };

method.setRequestBody(data);

// 执行

int status = httpClient.executeMethod(method);

// 得到返回

String response = new String(method.getResponseBody(),"UTF-8");

参考文档:http://www.ibm.com/developerworks/cn/opensource/os-httpclient/

Http Clinet使用的更多相关文章

  1. Expo大作战(一)--什么是expo,如何安装expo clinet和xde,xde如何使用

    简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人 ...

  2. Clinet/Server在工作线程中刷新页面数据的方法

    Worker线程不能修改UI线程的状态(比如文本框里面的内容).解决的办法是写一个用来更新文本框内容的函数,然后在Worker线程里面通过BeginInvoke来利用delegate调用这个函数更新文 ...

  3. Navicat 链接mysql 显示 Clinet dose not support authentication protocol request by server ;consider upgrading MySQL client

    1  在命令窗口 输入mysql -uroot -p 首先通过cmd进入mysql 2 更改加密方式 mysql> ALTER USER 'root'@'localhost' IDENTIFIE ...

  4. 本地安装Mysql后,navicat链接异常:Clinet dose not support authentication protocol request by server ; consider upgrading MySQL client

    第一步:首先通过cmd进入mysql 在命令窗口 输入:mysql -u root -p: 第二步:更改加密方式 mysql> ALTER USER 'root'@'localhost' IDE ...

  5. socket tcp clinet最简单测试程序

    // testsocketclient.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <winsock2.h> ...

  6. golang kafka clinet 内存泄露问题处理

    go 内存泄露 新版本服务跑上一天内存占用20g,显然是内存泄露 内存泄露的问题难在定位 技术上的定位 主要靠 pprof 生成统计文件 之前写web项目 基于net/http/pprof 可以看到运 ...

  7. X Window 的奥秘

    大名鼎鼎的 X Window 大家肯定不陌生.都知道它是 Unix/Linux 下面的窗口系统,也都知道它基于 Server/Clinet 架构.在网上随便搜一搜,也可以找到不少 X Window 的 ...

  8. ASP.NET Web API 开篇示例介绍

    ASP.NET Web API 开篇示例介绍 ASP.NET Web API 对于我这个初学者来说ASP.NET Web API这个框架很陌生又熟悉着. 陌生的是ASP.NET Web API是一个全 ...

  9. linux NFS 配置步骤

    转载 http://woxihuanpes.blog.163.com/blog/static/12423219820097139145238/ NFS server可以看作是一个FILE SERVER ...

随机推荐

  1. Ubuntu中安装编译并测试HTK语音识别库

    1.在网上看到首先必须确保电脑上安装了g++和libx11 g++ --version //检测g++版本 sudo apt-get install libx11-dev:i386 2.然后可从HTK ...

  2. uva 280 - Vertex

    #include <iostream> #include <cstdio> using namespace std; #include <vector> #defi ...

  3. C#模拟登录的htmlHelper类

    public class HTMLHelper { /// <summary> /// 获取CooKie /// /// </summary> /// /// <para ...

  4. 数学函数类方法的使用.java

    public class Test { public static void main(String[] args) { double a=2,b=3; double z1=Math.pow(a,b) ...

  5. 解决redis-cli连接时出现Could not connect to Redis at 127.0.0.1:6379: Connection refused

    执行redis 配置文件 redis-server  /etc/redis/redis.conf

  6. Git学习笔记01--初始化设置

    1.查看git版本 $ git --version 2.设置用户姓名和邮箱 $ git config --global user.name “Craftor” $ git config --globa ...

  7. Android面试题(文章内容来自他人博客)

    腾讯面试题 1.int a = 1; int result = a+++3<<2; 2.int a = 2; int result = (a++ > 2)?(++a):(a+=3); ...

  8. OC 冒泡排序 -- 核心代码

    //冒泡 核心代码 for (int i = 0; i < array.count - 1; i++) { int a = [array[i] intValue]; for (int j = i ...

  9. PHP 之mysql空字符串问题

    有一张user表如下所示:字段name不能为空. CREATE TABLE `user` ( `id` ) NOT NULL AUTO_INCREMENT, `name` ) NOT NULL, `a ...

  10. 在NGINX上配置HTTPS---血的教训--要重启NGINX

    重启,不是重载!!! 是STOP & START 而不是RELOAD!!! 纠结了好几天...(难道有的NGINX上不用重启????) 你妹的,上次也是,,PHP-FPM,将一个PHP的程序连 ...