use*_*764 6 post curl http chunked-encoding
我知道curl可以将数据发布到URL:
$ curl -X POST http://httpbin.org/post -d "hello"
{
  "args": {}, 
  "data": "", 
  "files": {}, 
  "form": {
    "hello": ""
  }, 
  "headers": {
    "Accept": "*/*", 
    "Content-Length": "5", 
    "Content-Type": "application/x-www-form-urlencoded", 
    "Host": "httpbin.org", 
    "User-Agent": "curl/7.50.1"
  }, 
  "json": null, 
  "origin": "64.238.132.14", 
  "url": "http://httpbin.org/post"
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以通过管道传递curl来实现同样的事情:
$ echo "hello" | curl -X POST http://httpbin.org/post -d @-
{
  "args": {}, 
  "data": "", 
  "files": {}, 
  "form": {
    "hello": ""
  }, 
  "headers": {
    "Accept": "*/*", 
    "Content-Length": "5", 
    "Content-Type": "application/x-www-form-urlencoded", 
    "Host": "httpbin.org", 
    "User-Agent": "curl/7.50.1"
  }, 
  "json": null, 
  "origin": "64.238.132.14", 
  "url": "http://httpbin.org/post"
}
Run Code Online (Sandbox Code Playgroud)
现在事情变得棘手了。我了解 http 传输编码和分块,例如发送多行文件:
(“silly”是一个包含多行文本的文件,如此处所示)
$ cat silly | curl -X POST --header "Transfer-Encoding: chunked" "http://httpbin.org/post" --data-binary @-
{
  "args": {}, 
  "data": "", 
  "files": {}, 
  "form": {
    "hello\nthere\nthis is a multiple line\nfile\n": ""
  }, 
  "headers": {
    "Accept": "*/*", 
    "Content-Length": "41", 
    "Content-Type": "application/x-www-form-urlencoded", 
    "Host": "httpbin.org", 
    "User-Agent": "curl/7.50.1"
  }, 
  "json": null, 
  "origin": "64.238.132.14", 
  "url": "http://httpbin.org/post"
}
Run Code Online (Sandbox Code Playgroud)
现在我想要做的是让curl从stdin读取一行,将其作为一个块发送,然后返回并再次读取stdin(这使我能够继续下去)。这是我的第一次尝试:
curl -X POST --header "Transfer-Encoding: chunked" "http://httpbin.org/post" -d @-
Run Code Online (Sandbox Code Playgroud)
它只在我按下 ctrl-D 时才工作一次,但这显然会结束curl 的执行。
有没有办法告诉curl“发送(使用块编码)我到目前为止给你的内容,然后返回标准输入以获取更多信息”?
非常感谢,我在这个问题上摸不着头脑有一段时间了!
|   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           4004 次  |  
        
|   最近记录:  |