HttpClient(4.3.5) - HTTP Request & HTTP Response
2016-07-30 11:58
302 查看
HTTP Request
All HTTP requests have a request line consisting a method name, a request URI and an HTTP protocol version.HttpClient supports out of the box all HTTP methods defined in the HTTP/1.1 specification:
GET,
HEAD,
POST,
PUT,
DELETE,
TRACEand
OPTIONS. There is a specific class for each method type.:
HttpGet,
HttpHead,
HttpPost,
HttpPut,
HttpDelete,
HttpTrace, and
HttpOptions.
The Request-URI is a Uniform Resource Identifier that identifies the resource upon which to apply the request. HTTP request URIs consist of a protocol scheme, host name, optional port, resource path, optional query, and optional fragment.
HttpGet httpget = new HttpGet( "http://www.google.com/search?hl=en&q=httpclient&btnG=Google+Search&aq=f&oq=");
HttpClient provides
URIBuilderutility class to simplify creation and modification of request URIs.
URI uri = new URIBuilder() .setScheme("http") .setHost("www.google.com") .setPath("/search") .setParameter("q", "httpclient") .setParameter("btnG", "Google Search") .setParameter("aq", "f") .setParameter("oq", "") .build(); HttpGet httpget = new HttpGet(uri); System.out.println(httpget.getURI());
stdout >
http://www.google.com/search?q=httpclient&btnG=Google+Search&aq=f&oq=
HTTP Response
HTTP response is a message sent by the server back to the client after having received and interpreted a request message. The first line of that message consists of the protocol version followed by a numeric status code and its associated textual phrase.HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK"); System.out.println(response.getProtocolVersion()); System.out.println(response.getStatusLine().getStatusCode()); System.out.println(response.getStatusLine().getReasonPhrase()); System.out.println(response.getStatusLine().toString());
stdout >
HTTP/1.1 200 OK HTTP/1.1 200 OK
相关文章推荐
- Retrofit源码分析
- Java网络通信之HttpClient
- 对抗式网络(Adversarial Network)-深度学习突破的机会
- Table of Contents - HttpClient
- CDN-内容分发网络
- Python案例-网络编程-使用RabbitMQ实现RPC简易分享
- VMware安装centos 6.3 连不上网络
- iOS开发网络篇之文件下载、大文件下载、断点下载
- TCP服务器,实现client发送消息,server接收消息
- SOCKET通信中TCP、UDP数据包大小的确定
- iOS开发网络篇—发送GET和POST请求(使用NSURLSession)
- iOS开发网络篇—使用ASI框架进行文件下载
- Java网络通信之HttpUrlConnection
- 7.Linux网络命令、以及配置文件
- 6.网络基础
- IP地址详解
- 网络游戏知识汇总
- ZigBee网络离开机制
- hdu 3416(最短路+最大流)
- 深度学习模型训练技巧