首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在heredoc中使用socat?

如何在heredoc中使用socat?
EN

Stack Overflow用户
提问于 2021-04-03 04:19:58
回答 1查看 50关注 0票数 3

如果我从终端输入文本,我可以用这种方式运行socat。

代码语言:javascript
复制
$ 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时,我得不到相同的输出。有没有人知道怎么用这里的文档?

代码语言:javascript
复制
$ 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
EN

回答 1

Stack Overflow用户

发布于 2021-04-06 09:48:22

我觉得我并不完全理解发生了什么,但我认为feel文档的结尾是在HTTP请求返回之前发出关闭流的信号。解决此问题的一种方法是使用FD选项shut-none。

代码语言:javascript
复制
socat -d -d - TCP4:httpbin.org:80,shut-none <<EOF
GET /get HTTP/1.1
Host: httpbin.org

EOF

但我不知道这有多可靠。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66924794

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档