curl,API 请求在 Insomnia 中有效,但在为 curl 生成的代码中无效

gen*_*bee 4 api curl insomnia

我在失眠症中有一个请求。当我通过 Insomnia 发送时,没问题。但是当我生成curl 的源代码时,它向我展示了这一点。

\n
curl --request POST \\\n  --url URL \\\n  --header 'Authorization: bearer XXX' \\\n  --header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \\\n  --cookie JSESSIONID=XXX \\\n  --form datasetFile=@FOLDER/producthierarchyl1-1.zip\n\n{"message":"Bad Request","logref":null,"path":null,"_embedded":{"errors":[{"message":"Required argument [Publisher datasetFile] not specified","logref":null,"path":"/datasetFile","_embedded":{},"_links":{}}]},"_links":{"self":{"href":"/data-api/public-api/v4/datasets/ingestion/","templated":false,"profile":null,"deprecation":null,"title":null,"hreflang":null,"type":null,"name":null}}}\n
Run Code Online (Sandbox Code Playgroud)\n

失眠输出是这样的。

\n
> POST PATH HTTP/2\n> Host: URL\n> user-agent: insomnia/2022.3.0\n> cookie: JSESSIONID=XXX\n> authorization: bearer XXX\n> content-type: multipart/form-data; boundary=X-INSOMNIA-BOUNDARY\n> accept: */*\n> content-length: 407\n\n* STATE: DO => DID handle 0x170404b14008; line 2077 (connection #27)\n* multi changed, check CONNECT_PEND queue!\n* STATE: DID => PERFORMING handle 0x170404b14008; line 2196 (connection #27)\n\n| --X-INSOMNIA-BOUNDARY\n| Content-Disposition: form-data; name="datasetFile"; filename="producthierarchyl1-1.zip"\n| Content-Type: application/zip\n| PK\xef\xbf\xbdQU\xef\xbf\xbd}\xef\xbf\xbd%+producthierarchyl1-1.csvUT  \xd5\xa2\xef\xbf\xbdb\n| --X-INSOMNIA-BOUNDARY--\n\n* We are completely uploaded and fine\n* HTTP/2 found, allow multiplexing\n
Run Code Online (Sandbox Code Playgroud)\n

陷阱在哪里?

\n

谢谢。

\n

Dan*_*erg 7

删除该--header 'content-type: multipart/form-data; boundary=---011000010111000001101001选项。

它确实不应该这样使用:curl 自行管理该标头和边界,因此只有在您真正想要并且需要摆弄它的罕见情况下才应该更改它。

更次要的第二件事:--request POST应该从命令行中删除,因为它是多余的,如果--location稍后添加,很容易导致问题。

更新

据说这个缺陷已在 Insomnia 的更高版本中得到修复