2017-04-12 90 views
-1

我試圖通過API將固件上傳到計算機,通常我通過點擊我們網絡服務器上的按鈕來完成。這是「一般」標題:我無法通過POST上傳我的文件cURL

Request URL:http://192.168.243.179:8080/firmware/linux/ 
Request Method:POST 
Status Code:200 OK 
Remote Address:192.168.243.179:8080 
Referrer Policy:no-referrer-when-downgrade 

在固件頁面,我會點擊一個按鈕,它上傳我的固件文件/固件/ LINUX /。

這是我的響應頭時,我提交了固件文件:

HTTP/1.1 200 OK 
Date: Tue, 11 Apr 2017 23:22:43 GMT 
Content-Length: 134 
Content-Type: text/html;charset=utf-8 
Server: CherryPy/3.2.2 

這裏是我的請求頭:

POST /firmware/linux HTTP/1.1 
Host: 192.168.243.179:8080 
Connection: keep-alive 
Content-Length: 63067756 
Cache-Control: max-age=0 
Origin: http://192.168.243.179:8080 
Upgrade-Insecure-Requests: 1 
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36 
Content-Type: multipart/form-data; boundary=---- 
WebKitFormBoundarynaUDhUWIArqOTvuC 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 
Referer: http://192.168.243.179:8080/firmware/ 
Accept-Encoding: gzip, deflate 
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6 

和我的要求有效載荷:

------WebKitFormBoundarynaUDhUWIArqOTvuC 
Content-Disposition: form-data; name="image"; filename="uImage-jjr-dvr- 
atlas_v1.0.1-16-g5e31aec" 
Content-Type: application/octet-stream 

------WebKitFormBoundarynaUDhUWIArqOTvuC-- 

我使用以下cURL命令模仿這些請求,將我的固件文件發送到計算機:

curl -i -X POST -d @"C:\Users\name\Documents\firmware/firmwarefile" http://192.168.243.179:8080/firmware/linux/ -H "Content-Type: multipart/form-data" 

上面產生了錯誤ValueError: Invalid boundary in multipart form: ''

我然後用邊界嘗試,因爲在我的請求頭供給:

curl -i -X POST -d @"C:\Users\name\Documents\firmware/firmwarefile" http://192.168.243.179:8080/firmware/linux/ -H 
"Content-Type: multipart/form-data; boundary=----WebKitFormBoundarynaUDhUWIArqOTvuC" 

上述命令的產率沒有任何錯誤,但然後我檢查是否固件已經更新,而且還沒有。

我是否正確發佈我的文件?我不明白爲什麼固件文件沒有被推送。

感謝您的幫助提前。

+0

說話很便宜,讓我看看代碼! (c)Linus Torvalds – webKnjaZ

回答

0

我已經從cURL的官方論壇獲得幫助,並收到了解決我的問題的電子郵件。

I am using the following cURL command to imitate these requests to POST my 
firmware file over to the computer: 

    *curl -i -X POST -d @"C:\Users\name\Documents\firmware/firmwarefile" 

首先,避免-X:

https://daniel.haxx.se/blog/2015/09/11/unnecessary-use-of-curl-x/

然後,只要你想多formposts你想-F,而不是-d:

https://ec.haxx.se/http-postvspost.html

上午我正確發佈我的文件?我不明白爲什麼固件文件沒有被推送。

我想首先參考curl書中的「HTTP multipart formposts」部分,如果在閱讀完該書後還有什麼不清楚的地方,請指明,我會盡量詳細說明回覆或澄清書章...

https://ec.haxx.se/http-multipart.html

-

/daniel.haxx.se

這是我最後的捲曲的命令,在成功提交該文件。

curl -i -F [email protected]"C:\Users\user\Documents\Firmware\firmwareFile" http://192.168.243.179:8080/firmware/file 
相關問題