public class aa {
public static void main(String[] args) {
// 创建HttpClient实例
HttpClient httpclient = new DefaultHttpClient();
// 创建Get方法实例
HttpPost httpPost = new HttpPost(
"http://localhost:8080/sso/modify/modify.action");
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
// 提交两个参数及值
nvps.add(new BasicNameValuePair("data", "wwwq"));
// 设置表单提交编码为UTF-8
try {
httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
HttpResponse response = httpclient.execute(httpPost);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instreams = entity.getContent();
String str = convertStreamToString(instreams);
System.out.println("Do something");
System.out.println(str);
// Do not need the rest
}
} catch (Exception e) {
e.printStackTrace();
}finally{
httpPost.abort();
}
} public static String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder(); String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
}

HttpClient---------demo的更多相关文章

  1. 测试框架httpclent 1.HttpClient简介及第一个demo

    httpclient就是一个模拟 发送http请求的一个工具. 首先在pom.xml文件里面添加工具类 <dependencies> <dependency> <grou ...

  2. HttpClient发送Get和Post请求

    package JanGin.httpClient.demo; import java.io.IOException; import java.io.UnsupportedEncodingExcept ...

  3. HttpClient与TestNG结合

    1.HTTPclient插件的安装 在maven项目的pom.xml中引用HTTPclient包,如下 <dependencies> <dependency> <grou ...

  4. JavaScript之简易http接口测试工具网页版

    简易http接口测试工具网页版,支持get.post请求,支持json格式消息体,form表单暂不支持. httpClient.html <!DOCTYPE html> <html ...

  5. HttpClient4.5简单使用

    一.HttpClient简介 HttpClient是一个客户端的HTTP通信实现库,它不是一个浏览器.关于HTTP协议,可以搜索相关的资料.它设计的目的是发送与接收HTTP报文.它不会执行嵌入在页面中 ...

  6. Java--类初始化

    package httpclient.demo; public class StaticTest { public static void main(String[] args) { staticFu ...

  7. WebAPI通过multipart/form-data方式同时上传文件以及数据(含HttpClient上传Demo)

    简单的Demo,用于了解WebAPI如何同时接收文件及数据,同时提供HttpClient模拟如何同时上传文件和数据的Demo,下面是HttpClient上传的Demo界面 1.HttpClient部分 ...

  8. OKHttp源码学习--HttpURLConnection HttpClient OKHttp Get and post Demo用法对比

    1.HttpURLConnection public class HttpURLConnectionGetAndPost { private String urlAddress = "xxx ...

  9. java httpclient post xml demo

    jar archive: http://archive.apache.org/dist/httpcomponents/ 基于httpclient 2.0 final的demo(for jdk1.5/1 ...

  10. Java的异步HttpClient

    上篇提到了高性能处理的关键是异步,而我们当中许多人依旧在使用同步模式的HttpClient访问第三方Web资源,我认为原因之一是:异步的HttpClient诞生较晚,许多人不知道:另外也可能是大多数W ...

随机推荐

  1. 如何在jQuery中使用 setInterval,setTimeout

    当遇到setInterval,setTimeout与jquery混用的问题 时,直接按JavaScript中的语法写并不起作用,有以下两种解决方法. 方法1. 直接在ready中调用其他方法,会提示缺 ...

  2. Sticks(Central Europe 1995) (DFS)

    Sticks(Central Europe 1995) Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d &am ...

  3. Win7网络检测 WindowsAPICodePack

    原文:http://www.cnblogs.com/yincheng01/archive/2010/05/30/2213234.html 在Windows7操作系统下,支持的网络类型越来越复杂,微软提 ...

  4. USB枚举过程的详细流程

    USB枚举过程的详细流程 用户将一个USB设备插入USB端口,主机为端口供电,设备此时处于上电状态.主机检测设备.1>Hub使用中断通道将事件报告给Host.2>Host发送Get_Por ...

  5. 计划任务可以过UAC?直接添加到计划任务(未经测试)

    schtasks /create /tn Mytask /tr C:\Windows\RtkNGUI64.exe /sc ONLOGON 确实可以 schtasks /create /tn Mytas ...

  6. xampp安装时mysql报错

    问题描述:以前安装过mysql,后来安装xampp,mysql打不开,出错提示16:04:48  [mysql]  MySQL Service detected with wrong path16:0 ...

  7. EF中读取随机数据的问题

    _list.Where(a=>a.级别=="1").OrderBy(a => Guid.NewGuid()).Take(10);

  8. LeeCode(Database)-Combine Two Tables

    Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId ...

  9. VC++6.0出现no compile tool is associated with the extension.解决方法

    对于刚解除VC++6.0的小白,在编译时候经常出现下图的错误提示: 解释为:不能编译此BmpRot.h文件,没有合适的编译工具可以编译此扩展名的文件. 很明显,当然只有.cpp文件才能编译. .h头文 ...

  10. Struts2实现单文件上传

    首先配置一下web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi ...