首页 > 构造http header,返回bad request

构造http header,返回bad request

以下是我自己构造的http header,

GET http://www.hao123.com/ HTTP/1.0
Host: www.hao123.com
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:26.0) Gecko/20100101 Firefox/26.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive

请问哪里有错.服务器返回

HTTP/1.0 400 Bad Request

现在一般都用HTTP/1.1协议


在Nginx中,多数是因为你申请的域名没有绑定,无法识别的请求,可以检查一下。Apache应该类似。


http请求 末尾必须有一个空行

https://tools.ietf.org/html/rfc2616#page-35

5 Request

A request message from a client to a server includes, within the
first line of that message, the method to be applied to the resource,
the identifier of the resource, and the protocol version in use.

    Request       = Request-Line              ; Section 5.1
                    *(( general-header        ; Section 4.5
                     | request-header         ; Section 5.3
                     | entity-header ) CRLF)  ; Section 7.1
                    CRLF
                    [ message-body ]          ; Section 4.3

注意request headers和message-body之间有一个CRLF(空行). GET虽然没有message-body, 这个空行还是要的.


curl 'http://www.hao123.com/' -H 'Host: www.hao123.com' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:26.0) Gecko/20100101 Firefox/26.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate' -H 'Connection: keep-alive' -o 'hao123.html'

按照你列出来的头部构造的,可以返回正确的内容(已经gzip,可以把Accept-Encoding去掉查看内容),所以应该是没构造好正确的请求。

【热门文章】
【热门文章】