HttpClient教程 基本原理
来源:互联网 发布:网络上hl是什么意思 编辑:程序博客网 时间:2024/06/05 12:00
原文:http://hc.apache.org/httpcomponents-client-4.5.x/tutorial/html/fundamentals.html
Chapter 1. Fundamentals
1.1. Request executionThe most essential function of HttpClient is to execute HTTP methods. Execution of an HTTP method involves one or several HTTP request / HTTP response exchanges, usually handled internally by HttpClient. The user is expected to provide a request object to execute and HttpClient is expected to transmit the request to the target server return a corresponding response object, or throw an exception if execution was unsuccessful.
Quite naturally, the main entry point of the HttpClient API is the HttpClient interface that defines the contract described above.
Here is an example of request execution process in its simplest form:
第一章:基本原理
1.1请求的执行
HttpClient最本质的功能是执行HTTP方法。一个HTTP方法的执行包含一次或多次的HTTP请求和HTTP响应,通常被HttpClient内部处理。用户提供一个请求对象去执行和HttpClient传输这个请求对象到目标服务器,目标服务器返回一个相应的结果对象,或者执行不成功则抛出一个异常对象。
很自然地,HttpClient API的主要入口点是定义了上述约定的HttpClient接口。
下面有一个最简单的请求执行过程例子
CloseableHttpClient httpclient = HttpClients.createDefault();HttpGet httpget = new HttpGet("http://localhost/");CloseableHttpResponse response = httpclient.execute(httpget);try { <...>} finally { response.close();}---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------1.1.1. 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, TRACE and 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.
1.1.1 HTTP 请求
所有的HTTP请求,都有一个请求行,包含方法名,请求URI和HTTP协议版本号。HttpClient支持的所有HTTP / 1.1规范中定义的HTTP方法:GET, HEAD, POST, PUT, DELETE, TRACE and OPTIONS。都有一个特定的类对应这些方法类型:HttpGet, HttpHead, HttpPost, HttpPut, HttpDelete, HttpTrace, and HttpOptions。
统一资源定位符Request-URI是确定哪一个资源被请求。请求URI由协议,域名,端口(可选),资源路径,查询和信息片段组成
HttpGet httpget = new HttpGet( "http://www.google.com/search?hl=en&q=httpclient&btnG=Google+Search&aq=f&oq=");
http://hc.apache.org/httpcomponents-client-4.5.x/tutorial/html/index.html
- HttpClient教程 基本原理
- HttpClient 教程 HttpClient Tutorial
- HttpClient 教程
- httpClient 教程
- HttpClient 教程
- httpClient 教程
- httpClient教程
- HttpClient教程
- HttpClient 教程
- HttpClient 教程
- HttpClient 教程
- HttpClient教程
- HttpClient 教程
- HttpClient教程
- HttpClient 教程
- Httpclient教程
- HttpClient 教程
- HttpClient教程
- AES 加密
- java 并发编程
- 史上最全的Web安全相关网址汇总【转帖】
- mybatis 返回map 一个项目使用另一个项目表中的三列数据
- iOS推送证书的生成
- HttpClient教程 基本原理
- jsp四大内置对象
- Ajax异步登录判断用户名密码的合法性
- wecenter二次开发系列(三)——多个wc框架同域网站共享cookie
- FFmpeg在iOS上完美编译
- [python 补充] _winreg
- 设置label.text的行间距
- 字符串相似度算法
- java this和super关键字