我想传递原始 HTTP 请求,例如:
GET /foo/bar HTTP/1.1
Host: example.org
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; fr; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8
Accept: */*
Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
X-Requested-With: XMLHttpRequest
Referer: http://example.org/test
Cookie: foo=bar; lorem=ipsum;
到 HTTP 客户端。
我尝试过
cat raw.http | curl
但没有成功。
有什么建议吗?
谢谢。
原始数据输入,原始数据输出:
nc example.org 80 < raw.http
如果您需要通过某个程序传输数据:
cat raw.http | someprogram | nc example.org 80
这个问题被标记为“curl”,所以我认为是时候给出一个“curl”的答案了
cat raw.http | curl "telnet://TARGETHOST:80"
为了正常使用,只需将 TARGETHOST 设置为与“host”标头值相同即可。
出于我的目的(不正常),我点击了一个 TARGETHOST,它是一个 IP 地址,其服务器正在侦听特定主机的主机标头。
请注意,如果您需要 httpS 而不是 http,那么这些解决方案都不起作用。在这种情况下,您可以这样发送:
$ cat raw.http | openssl s_client -connect server:443
在 bash 中,您可以使用
/dev/tcp/${host}/${port}
通过 tcp 发送原始数据。
# open a file descriptor channel for input and output
exec 3<>/dev/tcp/google.com/80
# send the raw request
echo -en "GET / HTTP/1.1\r\n\r\n" >&3
# read the raw response
cat <&3
# close the fd
exec 3<&-;exec 3>&-