[英]Request to Steam API working with curl, does not work in browser, insomnia nor flask
[英]curl, API request works in Insomnia, but not in generated code for curl
我有失眠的要求。 當我通過 Insomnia 發送時,沒問題。 但是當我為 curl 生成源代碼時,它向我展示了這一點。
curl --request POST \
--url URL \
--header 'Authorization: bearer XXX' \
--header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \
--cookie JSESSIONID=XXX \
--form datasetFile=@FOLDER/producthierarchyl1-1.zip
{"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}}}
失眠output就是這樣的。
> POST PATH HTTP/2
> Host: URL
> user-agent: insomnia/2022.3.0
> cookie: JSESSIONID=XXX
> authorization: bearer XXX
> content-type: multipart/form-data; boundary=X-INSOMNIA-BOUNDARY
> accept: */*
> content-length: 407
* STATE: DO => DID handle 0x170404b14008; line 2077 (connection #27)
* multi changed, check CONNECT_PEND queue!
* STATE: DID => PERFORMING handle 0x170404b14008; line 2196 (connection #27)
| --X-INSOMNIA-BOUNDARY
| Content-Disposition: form-data; name="datasetFile"; filename="producthierarchyl1-1.zip"
| Content-Type: application/zip
| PK�QU�}�%+producthierarchyl1-1.csvUT բ�b
| --X-INSOMNIA-BOUNDARY--
* We are completely uploaded and fine
* HTTP/2 found, allow multiplexing
問題在哪里?
謝謝。
刪除--header 'content-type: multipart/form-data; boundary=---011000010111000001101001
--header 'content-type: multipart/form-data; boundary=---011000010111000001101001
選項。
它真的不應該這樣使用:curl 管理 header 和它自己的邊界,所以改變它應該只在你真正想要並且需要擺弄它的罕見事件中進行。
次要的第二件事:-- --request POST
應該從命令行中刪除,因為它是多余的,並且如果您稍后添加--location
很容易導致問題。
據說這個漏洞已經在 Insomnia 的更高版本中得到修復
對於再次遇到此問題的任何人,此答案正確解釋了問題的原因。
幸運的是,這應該只能在版本 2022.3.0 和更早版本的 Insomnia 中重現。
如果使用最新的2022.5.1 ,生成的 curl 將不再有這個問題,生成多部分請求的示例:
curl --request GET \
--url http://mockbin.org/request/anything \
--header 'Content-Type: multipart/form-data' \
--form test=test \
--form test=@/Users/yourUserName/Desktop/somefile.txt
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.