htttp://www.fjedu.cn:

Apache Camel: HTTP
HTTP ComponentThe http: component provides HTTP based
for consuming external HTTP resources (as a client to call external servers using HTTP).Maven users will need to add the following dependency to their pom.xml for this component:
URI format
Will by default use port 80 for HTTP and 443 for HTTPS.ExamplesCall the url with the body using POST and return response as out message. If body is null call URL using GET and return response as out messageJava DSLSpring DSL
You can override the HTTP endpoint URI by adding a header. Camel will call the . This is very handy for e.g. REST urls.Java DSL
URI parameters can either be set directly on the endpoint URI or as a headerJava DSL
Set the HTTP request method to POSTJava DSLSpring DSL
HttpEndpoint OptionsNameDefault ValueDescriptionthrowExceptionOnFailuretrueOption to disable throwing the HttpOperationFailedException in case of failed responses from the remote server. This allows you to get all responses regardless of the HTTP status code.bridgeEndpointfalseIf the option is true , HttpProducer will ignore the Exchange.HTTP_URI header, and use the endpoint's URI for request. You may also set the * throwExceptionOnFailure* to be false to let the HttpProducer send all the fault response back.
Camel 2.3: If the option is true, HttpProducer and CamelServlet will skip the gzip processing if the content-encoding is "gzip".disableStreamCachefalseDefaultHttpBinding will copy the request input stream into a stream cache and put it into message body if this option is false to support read it twice, otherwise DefaultHttpBinding will set the request input stream direct into the message body. Camel 2.17: this options is now also support by the producer to allow using the response stream directly instead of stream caching as by default.httpBindingRefnullDeprecated and removed in Camel 2.17: Reference to a org.ponent.http.HttpBinding in the . Use the httpBinding option instead.httpBindingnullCamel 2.3: Reference to a org.ponent.http.HttpBinding in the .httpClientConfigurerRefnullDeprecated and removed in Camel 2.17: Reference to a org.ponent.http.HttpClientConfigurer in the . Use the httpClientConfigurer option instead.httpClientConfigurernullCamel 2.3: Reference to a org.ponent.http.HttpClientConfigurer in the .httpClient.XXXnullSetting options on the . For instance httpClient.soTimeout=5000 will set the SO_TIMEOUT to 5 seconds.clientConnectionManagernullTo use a custom org.apache.http.conn.ClientConnectionManager.transferExceptionfalseCamel 2.6: If enabled and an
failed processing on the consumer side, and if the caused Exception was send back serialized in the response as a application/x-java-serialized-object content type (for example using
Camel components). On the producer side the exception will be deserialized and thrown as is, instead of the HttpOperationFailedException. The caused exception is required to be serialized.headerFilterStrategynullCamel 2.11: Reference to a instance of org.apache.camel.spi.HeaderFilterStrategy in the . It will be used to apply the custom headerFilterStrategy on the new create HttpEndpoint.urlRewritenullCamel 2.11: Producer only Refers to a custom org.ponent.http.UrlRewrite which allows you to rewrite urls when you bridge/proxy endpoints. See more details at
and .eagerCheckContentAvailablefalseCamel 2.15.3/2.16: Consumer only  Whether to eager check whether the HTTP requests has content if the content-length header is 0 or not present.  This can be turned on in case HTTP clients do not send streamed data.copyHeaderstrueCamel 2.16:  If this option is true then IN exchange headers will be copied to OUT exchange headers according to copy strategy. Setting this to false, allows to only include the headers from the HTTP response (not propagating IN headers).okStatusCodeRange200-299Camel 2.16: The status codes which is considered a success response. The values are inclusive. The range must be defined as from-to with the dash included.ignoreResponseBodyfalseCamel 2.16: If this option is true, The http producer won't read response body and cache the input stream.Authentication and ProxyThe following authentication options can also be set on the HttpEndpoint:NameDefault ValueDescriptionauthMethodnullAuthentication method, either as Basic, Digest or NTLM.authMethodPrioritynullPriority of authentication methods. Is a list separated with comma. For example: Basic,Digest to exclude NTLM.authUsernamenullUsername for authenticationauthPasswordnullPassword for authenticationauthDomainnullDomain for NTML authenticationauthHostnullOptional host for NTML authenticationproxyHostnullThe proxy host nameproxyPortnullThe proxy port numberproxyAuthMethodnullAuthentication method for proxy, either as Basic, Digest or NTLM.proxyAuthUsernamenullUsername for proxy authenticationproxyAuthPasswordnullPassword for proxy authenticationproxyAuthDomainnullDomain for proxy NTML authenticationproxyAuthHostnullOptional host for proxy NTML authenticationWhen using authentication you must provide the choice of method for the authMethod or authProxyMethod options. You can configure the proxy and authentication details on either the HttpComponent or the HttpEndoint. Values provided on the HttpEndpoint will take precedence over HttpComponent. Its most likely best to configure this on the HttpComponent which allows you to do this once.The
component uses convention over configuration which means that if you have not explicit set a authMethodPriority then it will fallback and use the select(ed) authMethod as priority as well. So if you use authMethod.Basic then the auhtMethodPriority will be Basic only.Note: camel-http is based on HttpClient v3.x and as such has only
for what is known as NTLMv1, the early version of the NTLM protocol. It does not support NTLMv2 at all. Camel-http4 has support for NTLMv2.HttpComponent OptionsNameDefault ValueDescriptionhttpBindingnullTo use a custom org.ponent.http.HttpBinding.httpClientConfigurernullTo use a custom org.ponent.http.HttpClientConfigurer.httpConnectionManagernullTo use a custom mons.httpclient.HttpConnectionManager.httpConfigurationnullTo use a custom org.ponent.http.HttpConfigurationallowJavaSerializedObjectfalseCamel 2.16.1/2.15.5: Whether to allow java serialization when a request uses context-type=application/x-java-serialized-object. This is by default turned off. If you enable this then be aware that Java will deserialize the incoming data from the request to Java and that can be a potential security risk.HttpConfiguration contains all the options listed in the table above under the section HttpConfiguration - Setting Authentication and Proxy.NameTypeDescriptionExchange.HTTP_URIStringURI to call. Will override existing URI set directly on the endpoint. This uri is the uri of the http server to call. Its not the same as the Camel endpoint uri, where you can configure endpoint options such as security etc. This header does not support that, its only the uri of the http server.Exchange.HTTP_METHODStringHTTP Method / Verb to use (GET/POST/PUT/DELETE/HEAD/OPTIONS/TRACE)Exchange.HTTP_PATHStringRequest URI's path, the header will be used to build the request URI with the HTTP_URI. Camel 2.3.0: If the path is start with "/", http producer will try to find the relative path based on the Exchange.HTTP_BASE_URI header or the exchange.getFromEndpoint().getEndpointUri();Exchange.HTTP_QUERYStringURI parameters. Will override existing URI parameters set directly on the endpoint.Exchange.HTTP_RESPONSE_CODEintThe HTTP response code from the external server. Is 200 for OK.Exchange.HTTP_CHARACTER_ENCODINGStringCharacter encoding.Exchange.CONTENT_TYPEStringThe HTTP content type. Is set on both the IN and OUT message to provide a content type, such as text/html.Exchange.CONTENT_ENCODINGStringThe HTTP content encoding. Is set on both the IN and OUT message to provide a content encoding, such as gzip.Exchange.HTTP_SERVLET_REQUESTHttpServletRequestThe HttpServletRequest object.Exchange.HTTP_SERVLET_RESPONSEHttpServletResponseThe HttpServletResponse object.Exchange.HTTP_PROTOCOL_VERSIONStringCamel 2.5: You can set the http protocol version with this header, eg. "HTTP/1.0". If you didn't specify the header, HttpProducer will use the default value "HTTP/1.1"The header name above are constants. For the spring DSL you have to use the value of the constant instead of the name.Message BodyCamel will store the HTTP response from the external server on the OUT body. All headers from the IN message will be copied to the OUT message, so headers are preserved during routing. Additionally Camel will add the HTTP response headers as well to the OUT message headers.Response codeCamel will handle according to the HTTP response code:Response code is in the range 100..299, Camel regards it as a success response.Response code is in the range 300..399, Camel regards it as a redirection response and will throw a HttpOperationFailedException with the information.Response code is 400+, Camel regards it as an external server failure and will throw a HttpOperationFailedException with the information.HttpOperationFailedExceptionThis exception contains the following information:The HTTP status codeThe HTTP status line (text of the status code)Redirect location, if server returned a redirectResponse body as a java.lang.String, if server provided a body as responseCalling using GET or POSTThe following algorithm is used to determine if either GET or POST HTTP method should be used: 1. Use method provided in header. 2. GET if query string is provided in header. 3. GET if endpoint is configured with a query string. 4. POST if there is data to send (body is not null). 5. GET otherwise.How to get access to HttpServletRequest and HttpServletResponseYou can get access to these two using the Camel type converter system using
See the unit test in More ExamplesConfiguring a ProxyJava DSL
There is also support for proxy authentication via the proxyUsername and proxyPassword options.Java DSLSpring DSL
Options on Endpoint will override options on the context.Configuring charsetIf you are using POST to send data you can configure the charset
Sample with scheduled pollThe sample polls the Google homepage every 10 seconds and write the page to the file message.html:
Getting the Response CodeYou can get the HTTP response code from the HTTP component by getting the value from the Out message header with Exchange.HTTP_RESPONSE_CODE.
Using throwExceptionOnFailure=false to get any response backIn the route below we want to route a message that we
with data returned from a remote HTTP call. As we want any response from the remote server, we set the throwExceptionOnFailure option to false so we get any response in the AggregationStrategy. As the code is based on a unit test that simulates a HTTP status code 404, there is some assertion code etc.
Disabling CookiesTo disable cookies you can set the HTTP Client to ignore cookies by adding this URI option: httpClient.cookiePolicy=ignoreCookiesAdvanced UsageIf you need more control over the HTTP producer you should use the HttpComponent where you can set various classes to give you custom behavior.Setting MaxConnectionsPerHostThe
Component has a mons.httpclient.HttpConnectionManager where you can configure various global configuration for the given component. By global, we mean that any endpoint the component creates has the same shared HttpConnectionManager. So, if we want to set a different value for the max connection per host, we need to define it on the HTTP component and not on the endpoint URI that we usually use. So here comes:First, we define the http component in Spring XML. Yes, we use the same scheme name, http, because otherwise Camel will auto-discover and create the component with default settings. What we need is to overrule this so we can set our options. In the sample below we set the max connection to 5 instead of the default of 2.
And then we can just use it as we normally do in our routes:
Using preemptive authenticationAn end user reported that he had problem with authenticating with HTTPS. The problem was eventually resolved when he discovered the HTTPS server did not return a HTTP code 401 Authorization Required. The solution was to set the following URI option: httpClient.authenticationPreemptive=trueAccepting self signed certificates from remote serverSee this
from a mailing list discussion with some code to outline how to do this with the Apache Commons HTTP API.Setting up SSL for HTTP ClientUsing the JSSE Configuration UtilityAs of Camel 2.8, the HTTP4 component supports SSL/TLS configuration through the .  This utility greatly decreases the amount of component specific code you need to write and is configurable at the endpoint and component levels.  The following examples demonstrate how to use the utility with the HTTP4 component.The version of the Apache HTTP client used in this component resolves SSL/TLS information from a global "protocol" registry.  This component provides an implementation, org.ponent.http.SSLContextParametersSecureProtocolSocketFactory, of the HTTP client's protocol socket factory in order to support the use of the Camel JSSE Configuration utility.  The following example demonstrates how to configure the protocol registry and use the registered protocol information in a route.
Configuring Apache HTTP Client DirectlyBasically camel-http component is built on the top of Apache HTTP client, and you can implement a custom org.ponent.http.HttpClientConfigurer to do some configuration on the http client if you need full control of it.However if you just want to specify the keystore and truststore you can do this with Apache HTTP HttpClientConfigurer, for example:
And then you need to create a class that implements HttpClientConfigurer, and registers https protocol providing a keystore or truststore per example above. Then, from your camel route builder class you can hook it up like so:
If you are doing this using the Spring DSL, you can specify your HttpClientConfigurer using the URI. For example:
As long as you implement the HttpClientConfigurer and configure your keystore and truststore as described above, it will work fine.See Also
The Apache Software Foundation.
Apache Camel, Camel, Apache, the Apache feather logo, and the Apache Camel project logo are trademarks of The Apache Software Foundation.
All other marks mentioned may be trademarks or registered trademarks of their respective owners.HTTP 方法:GET 对比 POST
HTTP 方法:GET 对比 POST
两种最常用的 HTTP 方法是:GET 和 POST。
什么是 HTTP?
超文本传输协议(HTTP)的设计目的是保证客户机与服务器之间的通信。
HTTP 的工作方式是客户机与服务器之间的请求-应答协议。
web 浏览器可能是客户端,而计算机上的网络应用程序也可能作为服务器端。
举例:客户端(浏览器)向服务器提交 HTTP 请求;服务器向客户端返回响应。响应包含关于请求的状态信息以及可能被请求的内容。
两种 HTTP 请求方法:GET 和 POST
在客户机和服务器之间进行请求-响应时,两种最常被用到的方法是:GET 和 POST。
GET - 从指定的资源请求数据。
POST - 向指定的资源提交要被处理的数据
请注意,查询字符串(名称/值对)是在 GET 请求的 URL 中发送的:
/test/demo_form.asp?name1=value1&name2=value2
有关 GET 请求的其他一些注释:
GET 请求可被缓存
GET 请求保留在浏览器历史记录中
GET 请求可被收藏为书签
GET 请求不应在处理敏感数据时使用
GET 请求有长度限制
GET 请求只应当用于取回数据
请注意,查询字符串(名称/值对)是在 POST 请求的 HTTP 消息主体中发送的:
POST /test/demo_form.asp HTTP/1.1
name1=value1&name2=value2
有关 POST 请求的其他一些注释:
POST 请求不会被缓存
POST 请求不会保留在浏览器历史记录中
POST 不能被收藏为书签
POST 请求对数据长度没有要求
比较 GET 与 POST
下面的表格比较了两种 HTTP 方法:GET 和 POST。
后退按钮/刷新
数据会被重新提交(浏览器应该告知用户数据会被重新提交)。
可收藏为书签
不可收藏为书签
application/x-www-form-urlencoded
application/x-www-form-urlencoded 或 multipart/form-data。为二进制数据使用多重编码。
参数保留在浏览器历史中。
参数不会保存在浏览器历史中。
对数据长度的限制
是的。当发送数据时,GET 方法向 URL 添加数据;URL 的长度是受限制的(URL 的最大长度是 2048 个字符)。
对数据类型的限制
只允许 ASCII 字符。
没有限制。也允许二进制数据。
与 POST 相比,GET 的安全性较差,因为所发送的数据是 URL 的一部分。
在发送密码或其他敏感信息时绝不要使用 GET !
POST 比 GET 更安全,因为参数不会被保存在浏览器历史或 web 服务器日志中。
数据在 URL 中对所有人都是可见的。
数据不会显示在 URL 中。
其他 HTTP 请求方法
下面的表格列出了其他一些 HTTP 请求方法:
与 GET 相同,但只返回 HTTP 报头,不返回文档主体。
上传指定的 URI 表示。
删除指定资源。
返回服务器支持的 HTTP 方法。
把请求连接转换到透明的 TCP/IP 通道。&& 门户访问地址发生变更,新地址如下:当今web程序的开发技术真是百家争鸣,ASP.NET, PHP, JSP,Perl, AJAX 等等。 无论Web技术在未来如何发展,理解Web程序之间通信的基本协议相当重要, 因为它让我们理解了Web应用程序的内部工作. 本文将对HTTP协议进行详细的实例讲解,内容较多,希望大家耐心看。也希望对大家的开发工作或者测试工作有所帮助。使用Fiddler工具非常方便地捕获HTTP Request和HTTP Response,& 关于Fiddler工具的用法,请看我另一篇博客[]
什么是HTTP协议
协议是指计算机通信网络中两台计算机之间进行通信所必须共同遵守的规定或规则,超文本传输协议(HTTP)是一种通信协议,它允许将超文本标记语言(HTML)文档从Web服务器传送到客户端的浏览器
目前我们使用的是HTTP/1.1 版本
Web服务器,浏览器,代理服务器
当我们打开浏览器,在地址栏中输入URL,然后我们就看到了网页。 原理是怎样的呢?
实际上我们输入URL后,我们的浏览器给Web服务器发送了一个Request, Web服务器接到Request后进行处理,生成相应的Response,然后发送给浏览器, 浏览器解析Response中的HTML,这样我们就看到了网页,过程如下图所示
我们的Request 有可能是经过了代理服务器,最后才到达Web服务器的。
过程如下图所示
代理服务器就是网络信息的中转站,有什么功能呢?
1. 提高访问速度, 大多数的代理服务器都有缓存功能。
2. 突破限制, 也就是FQ了
3. 隐藏身份。
&URL(Uniform Resource Locator) 地址用于描述一个网络上的资源,& 基本格式如下
schema://host[:port#]/path/.../[?query-string][#anchor]
scheme&&&&&&&&&&&&&& 指定低层使用的协议(例如:http, https, ftp)
host&&&&&&&&&&&&&&&&&& HTTP服务器的IP地址或者域名
port#&&&&&&&&&&&&&&&& HTTP服务器的默认端口是80,这种情况下端口号可以省略。如果使用了别的端口,必须指明,例如 :8080/
path&&&&&&&&&&&&&&&&&& 访问资源的路径
query-string&&&&&& 发送给http服务器的数据
anchor-&&&&&&&&&&&& 锚
URL 的一个例子
/sj/test/test.aspx?name=sviergn&x=true#stuffSchema:
/sj/test/test.aspxQuery String:
name=sviergn&x=trueAnchor:
HTTP协议是无状态的
http协议是无状态的,同一个客户端的这次请求和上次请求是没有对应关系,对http服务器来说,它并不知道这两个请求来自同一个客户端。 为了解决这个问题, Web程序引入了Cookie机制来维护状态.
打开一个网页需要浏览器发送很多次Request
1. 当你在浏览器输入URL
的时候,浏览器发送一个Request去获取
的html.& 服务器把Response发送回给浏览器.
2. 浏览器分析Response中的 HTML,发现其中引用了很多其他文件,比如图片,CSS文件,JS文件。
3. 浏览器会自动再次发送Request去获取图片,CSS文件,或者JS文件。
4. 等所有的文件都下载成功后。 网页就被显示出来了。
HTTP消息的结构
先看Request 消息的结构,&& Request 消息分为3部分,第一部分叫Request line, 第二部分叫Request header, 第三部分是body. header和body之间有个空行, 结构如下图
第一行中的Method表示请求方法,比如"POST","GET",& Path-to-resoure表示请求的资源, Http/version-number 表示HTTP协议的版本号
当使用的是"GET" 方法的时候, body是为空的
比如我们打开博客园首页的request 如下
GET / HTTP/1.1Host:
抽象的东西,难以理解,老感觉是虚的, 所谓眼见为实, 实际见到的东西,我们才能理解和记忆。 我们今天用Fiddler,实际的看看Request和Response.
下面我们打开Fiddler 捕捉一个博客园登录的Request 然后分析下它的结构, 在Inspectors tab下以Raw的方式可以看到完整的Request的消息, & 如下图
我们再看Response消息的结构, 和Request消息的结构基本一样。 同样也分为三部分,第一部分叫Response line, 第二部分叫Response header,第三部分是body. header和body之间也有个空行,& 结构如下图
HTTP/version-number表示HTTP协议的版本号,& status-code 和message 请看下节[]的详细解释.
我们用Fiddler 捕捉一个博客园首页的Response然后分析下它的结构, 在Inspectors tab下以Raw的方式可以看到完整的Response的消息, & 如下图
Get和Post方法的区别
Http协议定义了很多与服务器交互的方法,最基本的有4种,分别是GET,POST,PUT,DELETE. 一个URL地址用于描述一个网络上的资源,而HTTP中的GET, POST, PUT, DELETE就对应着对这个资源的查,改,增,删4个操作。 我们最常见的就是GET和POST了。GET一般用于获取/查询资源信息,而POST一般用于更新资源信息.
我们看看GET和POST的区别
1. GET提交的数据会放在URL之后,以?分割URL和传输数据,参数之间以&相连,如EditPosts.aspx?name=test1&id=123456.& POST方法是把提交的数据放在HTTP包的Body中.
2. GET提交的数据大小有限制(因为浏览器对URL的长度有限制),而POST方法提交的数据没有限制.
3. GET方式需要使用Request.QueryString来取得变量的值,而POST方式通过Request.Form来获取变量的值。
4. GET方式提交数据,会带来安全问题,比如一个登录页面,通过GET方式提交数据时,用户名和密码将出现在URL上,如果页面可以被缓存或者其他人可以访问这台机器,就可以从历史记录获得该用户的账号和密码.
Response 消息中的第一行叫做状态行,由HTTP协议版本号, 状态码, 状态消息 三部分组成。
状态码用来告诉HTTP客户端,HTTP服务器是否产生了预期的Response.
HTTP/1.1中定义了5类状态码, 状态码由三位数字组成,第一个数字定义了响应的类别
1XX& 提示信息 - 表示请求已被成功接收,继续处理
2XX& 成功 - 表示请求已被成功接收,理解,接受
3XX& 重定向 - 要完成请求必须进行更进一步的处理
4XX& 客户端错误 -& 请求有语法错误或请求无法实现
5XX& 服务器端错误 -&& 服务器未能实现合法的请求
看看一些常见的状态码
最常见的就是成功响应状态码200了, 这表明该请求被成功地完成,所请求的资源发送回客户端
如下图, 打开博客园首页
重定向,新的URL会在response 中的Location中返回,浏览器将会自动使用新的URL发出新的Request
例如在IE中输入, . HTTP服务器会返回302, IE取到Response中Location header的新URL, 又重新发送了一个Request.
304 Not Modified
代表上次的文档已经被缓存了, 还可以继续使用,
例如打开博客园首页, 发现很多Response 的status code 都是304
提示: 如果你不想使用本地缓存可以用Ctrl+F5 强制刷新页面
400 Bad Request& 客户端请求与语法错误,不能被服务器所理解
403 Forbidden 服务器收到请求,但是拒绝提供服务
404 Not Found
请求资源不存在(输错了URL)
比如在IE中输入一个错误的URL, /tesdf.aspx
500 Internal Server Error 服务器发生了不可预期的错误
503 Server Unavailable 服务器当前不能处理客户端的请求,一段时间后可能恢复正常
HTTP Request header
使用Fiddler 能很方便的查看Reques header, 点击Inspectors tab -&Request tab-& headers& 如下图所示.
header 有很多,比较难以记忆,我们也按照Fiddler那样把header 进行分类,这样比较清晰也容易记忆。
Cache 头域
If-Modified-Since
作用: 把浏览器端缓存页面的最后修改时间发送到服务器去,服务器会把这个时间与服务器上实际文件的最后修改时间进行对比。如果时间一致,那么返回304,客户端就直接使用本地缓存文件。如果时间不一致,就会返回200和新的文件内容。客户端接到之后,会丢弃旧文件,把新文件缓存起来,并显示在浏览器中.
例如:If-Modified-Since: Thu, 09 Feb :57 GMT
实例如下图
If-None-Match
作用: If-None-Match和ETag一起工作,工作原理是在HTTP Response中添加ETag信息。 当用户再次请求该资源时,将在HTTP Request 中加入If-None-Match信息(ETag的值)。如果服务器验证资源的ETag没有改变(该资源没有更新),将返回一个304状态告诉客户端使用本地缓存文件。否则将返回200状态和新的资源和Etag.& 使用这样的机制将提高网站的性能
例如: If-None-Match: "03f2b33c0bfcc1:0"
实例如下图
作用: 防止页面被缓存, 在HTTP/1.1版本中,它和Cache-Control:no-cache作用一模一样
Pargma只有一个用法, 例如: Pragma: no-cache
注意: 在HTTP/1.0版本中,只实现了Pragema:no-cache, 没有实现Cache-Control
Cache-Control
作用: 这个是非常重要的规则。 这个用来指定Response-Request遵循的缓存机制。各个指令含义如下
Cache-Control:Public&& 可以被任何缓存所缓存()
Cache-Control:Private&&&& 内容只缓存到私有缓存中
Cache-Control:no-cache& 所有内容都不会被缓存
还有其他的一些用法, 我没搞懂其中的意思, 请大家参考其他的资料
Client 头域
作用:&浏览器端可以接受的媒体类型,
例如:& Accept: text/html &代表浏览器可以接受服务器回发的类型为 text/html &也就是我们常说的html文档,
如果服务器无法返回text/html类型的数据,服务器应该返回一个406错误(non acceptable)
通配符 * 代表任意类型
例如 &Accept: */* &代表浏览器可以处理所有类型,(一般浏览器发给服务器都是发这个)
Accept-Encoding:
作用: 浏览器申明自己接收的编码方法,通常指定压缩方法,是否支持压缩,支持什么压缩方法(gzip,deflate),(注意:这不是只字符编码);
例如: Accept-Encoding: gzip, deflate
Accept-Language
作用: 浏览器申明自己接收的语言。&
语言跟字符集的区别:中文是语言,中文有多种字符集,比如big5,gb2312,gbk等等;
例如: Accept-Language: en-us
User-Agent
作用:告诉HTTP服务器, 客户端使用的操作系统和浏览器的名称和版本.
我们上网登陆论坛的时候,往往会看到一些欢迎信息,其中列出了你的操作系统的名称和版本,你所使用的浏览器的名称和版本,这往往让很多人感到很神奇,实际上,服务器应用程序就是从User-Agent这个请求报头域中获取到这些信息User-Agent请求报头域允许客户端将它的操作系统、浏览器和其它属性告诉服务器。
例如:&User-Agent: Mozilla/4.0 ( MSIE 8.0; Windows NT 5.1; Trident/4.0; CIBA; .NET CLR 2.0.50727; .NET CLR 3.0.; .NET CLR 3.5.30729; .NET4.0C; InfoPath.2; .NET4.0E)
Accept-Charset
作用:浏览器申明自己接收的字符集,这就是本文前面介绍的各种字符集和字符编码,如gb2312,utf-8(通常我们说Charset包括了相应的字符编码方案);
Cookie/Login 头域
作用: 最重要的header, 将cookie的值发送给HTTP 服务器
Entity头域
Content-Length
作用:发送给HTTP服务器数据的长度。
例如: Content-Length: 38
Content-Type
例如:Content-Type: application/x-www-form-urlencoded
Miscellaneous 头域
作用: 提供了Request的上下文信息的服务器,告诉服务器我是从哪个链接过来的,比如从我主页上链接到一个朋友那里,他的服务器就能够从HTTP Referer中统计出每天有多少用户点击我主页上的链接访问他的网站。
例如: Referer:/?hl=zh-cn&tab=wT
Transport 头域
Connection
例如: Connection: keep-alive&& 当一个网页打开完成后,客户端和服务器之间用于传输HTTP数据的TCP连接不会关闭,如果客户端再次访问这个服务器上的网页,会继续使用这一条已经建立的连接
例如:& Connection: close& 代表一个Request完成后,客户端和服务器之间用于传输HTTP数据的TCP连接会关闭, 当客户端再次发送Request,需要重新建立TCP连接。
Host(发送请求时,该报头域是必需的)
作用: 请求报头域主要用于指定被请求资源的Internet主机和端口号,它通常从HTTP URL中提取出来的
例如: 我们在浏览器中输入:http://www./index.html
浏览器发送的请求消息中,就会包含Host请求报头域,如下:
Host:http://www.
此处使用缺省端口号80,若指定了端口号,则变成:Host:指定端口号
HTTP Response header
同样使用Fiddler 查看Response header, 点击Inspectors tab -&Response tab-& headers& 如下图所示
&我们也按照Fiddler那样把header 进行分类,这样比较清晰也容易记忆。
作用:& 生成消息的具体时间和日期
例如: Date: Sat, 11 Feb :14 GMT&
作用: 浏览器会在指定过期时间内使用本地缓存
例如: Expires: Tue, 08 Feb :14 GMT
例如: Vary: Accept-Encoding
Cookie/Login 头域
作用: 用于跨域设置Cookie, 这样可以解决iframe跨域访问cookie的问题
例如: P3P: CP=CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR
Set-Cookie
作用: 非常重要的header, 用于把cookie 发送到客户端浏览器, 每一个写入cookie都会生成一个Set-Cookie.
例如: Set-Cookie: sc=4c31523a; path=/; domain=.
Entity头域
作用:& 和If-None-Match 配合使用。 (实例请看上节中If-None-Match的实例)
例如: ETag: "03f2b33c0bfcc1:0"
Last-Modified:
作用: 用于指示资源的最后修改日期和时间。(实例请看上节的If-Modified-Since的实例)
例如: Last-Modified: Wed, 21 Dec :10 GMT
Content-Type
作用:WEB服务器告诉浏览器自己响应的对象的类型和字符集,
Content-Type: text/ charset=utf-8
Content-Type:text/charset=GB2312
Content-Type: image/jpeg
Content-Length
指明实体正文的长度,以字节方式存储的十进制数字来表示。在数据下行的过程中,Content-Length的方式要预先在服务器中缓存所有数据,然后所有数据再一股脑儿地发给客户端。
例如: Content-Length: 19847
Content-Encoding
WEB服务器表明自己使用了什么压缩方法(gzip,deflate)压缩响应中的对象。
例如:Content-Encoding:gzip
Content-Language
作用: WEB服务器告诉浏览器自己响应的对象的语言者
例如: Content-Language:da
Miscellaneous 头域
作用:指明HTTP服务器的软件信息
例如:Server: Microsoft-IIS/7.5
X-AspNet-Version:
作用:如果网站是用ASP.NET开发的,这个header用来表示ASP.NET的版本
例如: X-AspNet-Version: 4.0.30319
X-Powered-By:
作用:表示网站是用什么技术开发的
例如: X-Powered-By: ASP.NET
Transport头域
Connection
例如: Connection: keep-alive&& 当一个网页打开完成后,客户端和服务器之间用于传输HTTP数据的TCP连接不会关闭,如果客户端再次访问这个服务器上的网页,会继续使用这一条已经建立的连接
例如:& Connection: close& 代表一个Request完成后,客户端和服务器之间用于传输HTTP数据的TCP连接会关闭, 当客户端再次发送Request,需要重新建立TCP连接。
Location头域
作用: 用于重定向一个新的位置, 包含新的URL地址
&实例请看304状态实例
HTTP协议是无状态的和Connection: keep-alive的区别
无状态是指协议对于事务处理没有记忆能力,服务器不知道客户端是什么状态。从另一方面讲,打开一个服务器上的网页和你之前打开这个服务器上的网页之间没有任何联系
HTTP是一个无状态的面向连接的协议,无状态不代表HTTP不能保持TCP连接,更不能代表HTTP使用的是UDP协议(无连接)
从HTTP/1.1起,默认都开启了Keep-Alive,保持连接特性,简单地说,当一个网页打开完成后,客户端和服务器之间用于传输HTTP数据的TCP连接不会关闭,如果客户端再次访问这个服务器上的网页,会继续使用这一条已经建立的连接
&Keep-Alive不会永久保持连接,它有一个保持时间,可以在不同的服务器软件(如Apache)中设定这个时间
///////////////////////////////////////////////////////////
本文转载自&
/TankXiao/
/TankXiao/archive//2342672.html
阅读(...) 评论()}

我要回帖

更多关于 1649cc天空彩票tkcp.cc 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信