如果我从终端输入文本,我可以用这种方式运行socat。
$ socat -d -d - TCP4:httpbin.org:80
2021/04/02 15:12:43 socat[22364] N reading from and writing to stdio
2021/04/02 15:12:43 socat[22364] N opening connection to LEN=16 AF=2 34.199.75.4:80
2021/04/02 15:12:43 socat[22364] N successfully connected from local address LEN=16 AF=2 10.1.186.126:57360
2021/04/02 15:12:43 socat[22364] N starting data transfer loop with FDs [0,1] and [7,7]
GET /get HTTP/1.1
Host: myhost
HTTP/1.1 200 OK
Date: Fri, 02 Apr 2021 20:12:59 GMT
Content-Type: application/json
Content-Length: 190
Connection: keep-alive
Server: gunicorn/19.9.0
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
{
"args": {},
"headers": {
"Host": "myhost",
"X-Amzn-Trace-Id": "Root=1-60677acb-1e2c974a0fb9bee97b8072dd"
},
"origin": "XXX.XXX.XXX.XXX",
"url": "http://myhost/get"
}但是当我使用heredoc时,我得不到相同的输出。有没有人知道怎么用这里的文档?
$ socat -d -d - TCP4:httpbin.org:80 <<EOF
GET /get HTTP/1.1
Host: httpbin.org
EOF
2021/04/02 15:16:42 socat[22870] N reading from and writing to stdio
2021/04/02 15:16:42 socat[22870] N opening connection to LEN=16 AF=2 54.166.163.67:80
2021/04/02 15:16:42 socat[22870] N successfully connected from local address LEN=16 AF=2 10.1.186.126:58356
2021/04/02 15:16:42 socat[22870] N starting data transfer loop with FDs [0,1] and [7,7]
2021/04/02 15:16:42 socat[22870] N socket 1 (fd 0) is at EOF
2021/04/02 15:16:42 socat[22870] N socket 2 (fd 7) is at EOF
2021/04/02 15:16:42 socat[22870] N exiting with status 0发布于 2021-04-06 09:48:22
我觉得我并不完全理解发生了什么,但我认为feel文档的结尾是在HTTP请求返回之前发出关闭流的信号。解决此问题的一种方法是使用FD选项shut-none。
socat -d -d - TCP4:httpbin.org:80,shut-none <<EOF
GET /get HTTP/1.1
Host: httpbin.org
EOF但我不知道这有多可靠。
https://stackoverflow.com/questions/66924794
复制相似问题