Examples of HttpRequest


转自: http://www.massapi.com/class/ht/HttpRequest.html


Examples of HttpRequest

Otherwise, the HTTP request will go directly to the host:
  • connect opens a connection to the remote host.
  • uses the "Connection" header to keep alive the connection.
  • sends a host-relative URL in the request line, for example "/index.html". The relative URL is derived from the fully qualified URL used to construct this HttpRequest.
header "Connection" or "Proxy-Connection"
The  HttpRequest sets the appropriate connection header to "Keep-Alive" to keep alive the connection to the host or proxy (respectively). By setting the appropriate connection header, the user can control whether the  HttpRequesttries to use Keep-Alives.
header "Host"
The HTTP/1.1 protocol requires that the "Host" header be set to the name of the machine being contacted. By default, this is derived from the URL used to construct the  HttpRequest, and is set automatically if the user does not set it.
header "Content-Length"
If the user calls  getOutputStream and writes some data to it, the "Content-Length" header will be set to the amount of data that has been written at the time that  connect is called.
Once all data has been read from the remote host, the underlying socket may be automatically recycled and used again for subsequent requests to the same remote host. If the user is not planning on reading all the data from the remote host, the user should call  close to release the socket. Although it happens under the covers, the user should be aware that if an IOException occurs or once data has been read normally from the remote host,  close is called automatically. This is to ensure that the minimal number of sockets are left open at any time.

The input stream that getInputStream provides automatically hides whether the remote host is providing HTTP/1.1 "chunked" encoding or regular streaming data. The user can simply read until reaching the end of the input stream, which signifies that all the available data from this request has been read. If reading from a "chunked" source, the data is automatically de-chunked as it is presented to the user. Currently, no access is provided to the underlying raw input stream. @author Colin Stevens (colin.stevens@sun.com) @version 2.5

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值