HTTP Post Request using Apache Commons
Demonstrates an HTTP Post using the Apache Commons HTTP library.
Required Libraries:
- httpcore-4.1.jar
- commons-io-2.4.jar
- commons-logging-1.1.1.jar
- httpmime-4.1.1.jar
- httpclient-4.1.1.jar
Example Source Code
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List; import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair; public class ExampleHttpPost
{
public static void main(String args[]) throws ClientProtocolException, IOException
{
HttpPost httppost = new HttpPost("https://stanfordwho.stanford.edu/SWApp/Search.do"); List<BasicNameValuePair> parameters = new ArrayList<BasicNameValuePair>();
parameters.add(new BasicNameValuePair("search", "jsproch"));
parameters.add(new BasicNameValuePair("filters", "closed"));
parameters.add(new BasicNameValuePair("affilfilter", "everyone"));
parameters.add(new BasicNameValuePair("btnG", "Search")); httppost.setEntity(new UrlEncodedFormEntity(parameters)); HttpClient httpclient = new DefaultHttpClient();
HttpResponse httpResponse = httpclient.execute(httppost);
HttpEntity resEntity = httpResponse.getEntity(); // Get the HTTP Status Code
int statusCode = httpResponse.getStatusLine().getStatusCode(); // Get the contents of the response
InputStream input = resEntity.getContent();
String responseBody = IOUtils.toString(input);
input.close(); // Print the response code and message body
System.out.println("HTTP Status Code: "+statusCode);
System.out.println(responseBody);
}
}
HTTP Post Request using Apache Commons的更多相关文章
- Unable to parse request org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. null
最近做一个web项目中有上传文件的功能,已经写出并在本地和部署到服务器上测试了好几个文件上传都没问题(我用的是tomcat).部署上服务器,上传图片时有的图片大就回在tomcat日志报如下错误: Un ...
- 上传文件出错:org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly
最近做一个web项目中有上传文件的功能,已经写出并在本地和部署到服务器上测试了好几个文件上传都没问题(我用的是tomcat).后来又上传了一个700多K的文件(前边的都是不足600K的,并且这个wor ...
- Could not parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed.
org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nes ...
- org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected be
1.错误描写叙述 八月 14, 2015 3:03:05 下午 com.opensymphony.xwork2.util.logging.jdk.JdkLogger warn 警告: Request ...
- Apache Commons BeanUtils
http://commons.apache.org/proper/commons-beanutils/javadocs/v1.9.2/apidocs/org/apache/commons/beanut ...
- CVE-2014-0050: Exploit with Boundaries, Loops without Boundaries、Apache Commons FileUpload and Apache Tomcat DoS
catalog . Description . Analysis . POC . Solution 1. Description MultipartStream.java in Apache Comm ...
- Apache Commons fileUpload实现文件上传之一
需要两个jar包: commons-fileupload.jar Commons IO的jar包(本文使用commons-io-2.4.jar) 利用Servlet来实现文件上传. package ...
- Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException:
七月 17, 2014 4:56:01 下午 org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service( ...
- Apache Commons 工具集使用简介
Apache Commons包含了很多开源的工具,用于解决平时编程经常会遇到的问题,减少重复劳动.我选了一些比较常用的项目做简单介绍.文中用了很多网上现成的东西,我只是做了一个汇总整理. 一.Comm ...
随机推荐
- 【转】TLB(Translation Lookaside Buffers,TLB)的作用
原文网址:http://sdnydubing.blog.163.com/blog/static/137470570201122810503396/ 从虚拟地址到物理地址的转换过程可知:使用一级页表进行 ...
- Linux如何统计进程的CPU利用率
1.0 概述 在Linux的/proc文件系统,可以看到自启动时候开始,所有CPU消耗的时间片:对于个进程,也可以看到进程消耗的时间片.这是一个累计值,可以"非阻塞"的输出.获得一 ...
- UML类图设计
大纲: 在Visio里,包和类的关系是包含关系,将类拖入包的文件夹之后,关系就建立了,二元关联符号可以设置为:聚合.合成.接口:空心圆+直线(唐老鸭类实现了‘讲人话’):依赖:虚线+箭头(动物和空气的 ...
- mvc项目,导出到Excel,中文显示乱码
1 public class HomeController : Controller 2 { 3 static List<User> GetUsers() 4 { 5 List< ...
- 2014年acm亚洲区域赛·鞍山站
今天北京赛站的比赛也结束了···看了一天的直播之后意识到鞍山站的比赛都过去了一个多月了···这一个月比较萎靡···整天都在睡觉写报告画工图中度过··· 鞍山比哈尔滨还是暖和很多的···就是山上有奇怪的 ...
- HDU 5875 Function
Function Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- C# 好用的三层架构,项目直接上手用
一.项目结构 注意:1.Common类中的引用添加:右键--添加引用--.NET--选择对应的引用 2.各层之间引用互相添加(这个就不必多说了,三层最基础部分) 3.在添加 Oracle 引用时候 ...
- Delphi中编辑word
其他(28) //启动Word try wordapplication1.connect; except messagedlg('word may not be ins ...
- 遍历 集合 Dictionary 的时候修改集合 方法
Dictionary<string, string> dic = new Dictionary<string, string>(); dic.Add("1" ...
- [Hive - LanguageManual] Archiving for File Count Reduction
Archiving for File Count Reduction Note: Archiving should be considered an advanced command due to t ...