原始http请求:为什么我会收到400 Bad Request错误?

时间:2010-07-18 12:13:07

标签: rebol

我输入了这段代码:

p: open tcp://rebol.com:80
insert p "HEAD / HTTP/1.1 ^/"
insert p "Host: rebol.com/ ^/^/"
while [data: copy p][prin data]

第一行输出是400 Bad Request

>> p: open tcp://rebol.com:80
>> insert p "HEAD / HTTP/1.1 ^/"
>> insert p "Host: rebol.com/ ^/^/"
>> while [data: copy p][prin data]
HTTP/1.1 400 Bad Request
Date: Sun, 18 Jul 2010 12:10:49 GMT
Server: Apache/1.3.42 (Unix) PHP/4.4.9 mod_log_bytes/1.2 mod_bwlimited/1.4 mod_auth_passthrough/1.8 FrontPage
/5.0.2.2635 mod_ssl/2.8.31 OpenSSL/0.9.8e-fips-rhel5
Connection: close
Content-Type: text/html; charset=iso-8859-1

>>

为什么我会收到400 Bad Request?

2 个答案:

答案 0 :(得分:1)

我认为Host标头可能没有尾部斜杠。

答案 1 :(得分:1)

西蒙是对的,我想。

我认为这就是你想要的:

p: open tcp://rebol.com:80
insert p "HEAD / HTTP/1.1 ^/"
insert p "Host: rebol.com^/^/"
while [data: first p][prin data]

    HTTP/1.1 200 OK
    Date: Sun, 18 Jul 2010 12:28:19 GMT
    Server: Apache/1.3.42 (Unix) [.....]
    Last-Modified: Thu, 15 Jul 2010 18:59:21 GMT
    ETag: "3d0121-1c2a-4c3f5a89"
    Accept-Ranges: bytes
    Content-Length: 7210
    Content-Type: text/html

这可能是另一种方式:

p: open http://rebol.com
probe p/locals/headers
make object! [
    Date: "Sun, 18 Jul 2010 12:30:34 GMT"
    Server: {Apache/1.3.42 (Unix) [....]
    Last-Modified: "Thu, 15/Jul/2010/18:59:21/+GMT"
    Accept-Ranges: "bytes"
    Content-Encoding: none
    Content-Type: "text/html"
    Content-Length: "7210"
    Location: none
    Expires: none
    Referer: none
    Connection: "close"
    Authorization: none
    ETag: {"3d0121-1c2a-4c3f5a89"}
 ]