gpt4 book ai didi

linux - curl:来自 CLI 的每个文件附加 header (用于多部分 POST、SOAP 等)

转载 作者:太空狗 更新时间:2023-10-29 11:41:51 31 4
gpt4 key购买 nike

我尝试添加 Content-ID: 与其他一些自定义 header 一样长,仅使用 curl 和命令行( header 不应来自文件),并且对于同一请求中的每个附件,它们应该不同。但目前我只能指定每个文件的内容类型(已记录)。我没有为我的任务找到任何文档示例。

我使用类似的东西:

curl -X POST --form "file=@test1.txt" --form "file=@test2.jpg" http://host:port

结果如下(使用 wireshark 重构)。默认情况下没有TEST 词(见下文)。

POST / HTTP/1.1
Host: host:port
User-Agent: curl/7.52.1
Accept: */*
Content-Length: 408
Expect: 100-continue
Content-Type: multipart/form-data; boundary=------------------------d7a9fdc4812ebc3b

[SERVER REPLY:] HTTP/1.1 100 Continue

--------------------------d7a9fdc4812ebc3b
Content-Disposition: form-data; name="file"; filename="test1.txt"
Content-Type: text/plain
TEST <-- This is from _curl_ C code bruteforce. Here should be "Content-ID:from_command_line_for_file_1"

CONTENTS_OF_test1.txt
line2
line3

--------------------------d7a9fdc4812ebc3b
Content-Disposition: form-data; name="file"; filename="test2.jpg"
Content-Type: image/jpeg
TEST <-- This is from _curl_ C code bruteforce. Here should be "Content-ID:from_command_line_for_file_2"

CONTENTS_OF_test2.jpg
line2
line3

--------------------------d7a9fdc4812ebc3b--

为了查看 curl 是否可行,我深入研究了它的源代码。在“formdata.c”行 ~1290 处,是我的确切任务的代码。但是如何激活这个代码呢?为了确认这段代码是否真的用于每个文件的处理,我对其进行了暴力测试,并且它有效(参见上面的“测试”字样)。

     curList = file->contentheader;
while(curList) {
/* Process the additional headers specified for this form */
result = AddFormDataf(&form, &size, "\r\n%s", curList->data);
if(result)
break;
curList = curList->next;
}
// my bruteforce added line for test:
result = AddFormDataf(&form, &size, "\r\n%s", "TEST");

看起来 curl 已经支持我的任务,但是如何使用它,以及我应该通过命令行传递哪些参数(而不是通过/来自某些文件)?

man curl 对此没有太多建议,但它说“请参阅手册中的更多示例和详细信息”,但我找不到有用的东西。

curl 7.52.1

谢谢。

最佳答案

在 curl 7.58.0 中,您现在可以 add headers to a part in a multipart request像这样:

curl -F "upload=@foo.txt;headers=\"X-My-Hdr: 42\"" http://host.com/path

关于linux - curl:来自 CLI 的每个文件附加 header (用于多部分 POST、SOAP 等),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42150060/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com