Apache HttpComponents POST提交带参数提交
2024-10-18 22:32:40
public class Test { public static void main(String[] args) throws IOException { DefaultHttpClient httpclient = new DefaultHttpClient();
try { HttpPost httpost = new HttpPost("http://localhost:8080/task/index.jsp"); List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("IDToken1", "username"));
nvps.add(new BasicNameValuePair("IDToken2", "password")); httpost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8)); HttpResponse response = httpclient.execute(httpost);
HttpEntity entity = response.getEntity(); System.out.println("Login form get: " + response.getStatusLine());
EntityUtils.consume(entity); System.out.println("Post logon cookies:");
List<Cookie> cookies = httpclient.getCookieStore().getCookies();
if (cookies.isEmpty()) {
System.out.println("None");
} else {
for (int i = 0; i < cookies.size(); i++) {
System.out.println("- " + cookies.get(i).toString());
}
}
} finally {
httpclient.getConnectionManager().shutdown();
}
} }
最新文章
- Python *与** 参数问题
- 如何让老式浏览器支持html5新增的语义元素
- cookie与session的爱恨情仇
- C#调用杀毒软件MSE扫描指定目录或文件
- 在linux中使用phpize安装php扩展模块
- Oracle中删除重复的经典方案
- hadoop拾遗(一)---- 避免切分map文件
- 插入三层treeview代码
- Java 计算两个日期相差月数
- 先学习Oracle 11g的Automatic Diagnostic Repository新功能
- gulp入门详细教程
- 【NOIP 2017】逛公园
- 序号生成算法odoo
- 跟未名学Office - PPT核心:表达
- MongoDB的Invalid credentials for database
- 铺音out2
- 安装R语言的包的方法
- Integer与int的种种比较你知道多少
- TCGA数据批量下载
- Ubuntu 开启telnet、ftp服务
热门文章
- 【LeetCode】144. Binary Tree Preorder Traversal (3 solutions)
- javascript中function和object的区别,以及javascript如何实现面向对象的编程思想.
- OGG_GoldenGate数据控制进程Manager(案例)
- 文件描述符file descriptor与inode的相关知识
- &;lt;&;lt;Python基础教程&;gt;&;gt;学习笔记 | 第10章 | 充电时刻
- kubernetes 二
- USB的中断说明
- appserv - 最简单的绑定路径
- 【Android】3.8 定位图层展示
- node-inspector调试报错问题处理