0
我正嘗試使用curl將數據上傳到Web服務器。我分析了向服務器發送的數據,從一個瀏覽器,使用Wireshark的,如下圖所示:卷頁頭信息
POST /cgi-bin/upload.cgi HTTP/1.1
Host: 192.168.1.22
Connection: keep-alive
Content-Length: 2637
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Origin: http://192.168.1.22
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/30.0.1599.101 Safari/537.36
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryn1sckmiVOVfCwUMQ
Referer: http://192.168.1.22/upload.html
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
我看着瀏覽器訪問上載信息的網頁,如下圖所示:
<form method="POST" enctype="multipart/form-data" action="http://192.168.1.22/cgi-bin/upload.cgi">
File to upload:
<input type="file" name="theupload"><br>
Should it be updated?<input type="checkbox" name="configuration"><br>
<input type="submit" value="Press"> to upload the file!
</form>
我嘗試使用:
curl --referer http://192.168.1.22/upload.html -F [email protected] -F config=on http://192.168.1.22:80/cgi-bin/upload.cgi
我的產量
POST /cgi-bin/upload.cgi HTTP/1.1
User-Agent: curl/7.33.0
Host: 192.168.1.22
Accept: */*
Referer: http://192.168.1.22/upload.html
Content-Length: 2650
Expect: 100-continue
Content-Type: multipart/form-data; boundary=------------------------fd126312049d1f47
服務器返回HTTP/1.1 417期望失敗。 我只是在學習捲曲,而我不確定該怎麼做。我是否需要儘可能模仿瀏覽器命令的標題?或者是什麼可能把它扔掉的邊界? 感謝您的幫助。
它工作,很棒。謝謝。爲什麼「預期」字符串是默認的? – engineer14
@ user2558056 curl默認使用[14.20 Expect](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html)標題,因爲它是http 1.1客戶端,在發送主體詢問服務器之前「你接受它嗎? ?「,您的案例中的Web服務器或代理不理解此行爲 –