2017-05-24 56 views
0

我的目標,捲曲一個FileUpload裏面添加值的多形式

我嘗試自動切換到以太網嵌入式設備上的一些文件。爲此,我創建了一個批處理文件,用於在我的計算機上使用curl來發送文件上傳的POST。

我的問題

可悲的是我需要的多形式的「文件 - 部分」內的一些特殊值。 (name = uploadfile & filename = index.htm)我知道如何向多部分表單添加更多值,但我不知道如何將值添加到以多部分形式封裝的「文件部分」

我的問題

我怎麼能添加更多的信息/值的多形式捲曲的「文件 - 部分」?它甚至可以從批處理文件中捲曲嗎?

這是請求應該什麼樣子:

POST /cgi-bin/fs_fileupload.cgi HTTP/1.1 
Host: 192.168.1.72 
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Language: en-US,en;q=0.5 
Accept-Encoding: gzip, deflate 
DNT: 1 
Referer: http://192.168.1.72/files.html 
Connection: keep-alive 
Content-Length: 21930 
Content-Type: multipart/form-data; boundary=---------------------------86458141819368430751619760852 

-----------------------------86458141819368430751619760852 
Content-Disposition: form-data; name="uploadfile"; filename="index.htm" 
Content-Type: text/html 

<html> 
... 
... 
</html> 

-----------------------------86458141819368430751619760852 
Content-Disposition: form-data; name="path" 

/
-----------------------------86458141819368430751619760852 
Content-Disposition: form-data; name="submit" 

upload 
-----------------------------86458141819368430751619760852-- 

我的嵌入式系統需要的「文件 - 第二部分」中的條目:

內容處置:表格數據;命名=一個 「UploadFile」;文件名= 「index.htm的」 的Content-Type:text/html的

我嘗試次數

集全球各種形式的值:

捲曲-v -X POST -H「期望:」-F「[email protected];」 -F path =/-F submit = upload http://url/cgi-bin/fs_fileupload.cgi --trace-ascii/dev/stdout

這是從捲曲側起作用的。我在多部分表單級別上看到了添加到POST中的值。

== Info: Trying 192.168.1.72... 
== Info: TCP_NODELAY set 
== Info: Connected to 192.168.1.72 (192.168.1.72) port 80 (#0) 
=> Send header, 211 bytes (0xd3) 
0000: POST /cgi-bin/fs_fileupload.cgi HTTP/1.1 
002a: Host: 192.168.1.72 
003e: User-Agent: curl/7.54.0 
0057: Accept: */* 
0064: Content-Length: 22084 
007b: Content-Type: multipart/form-data; boundary=-------------------- 
00bb: ----18bc7d9c1cff49ca 
00d1: 
=> Send data, 153 bytes (0x99) 
0000: --------------------------18bc7d9c1cff49ca 
002c: Content-Disposition: form-data; name="file"; filename="index.htm 
006c: " 
006f: Content-Type: application/octet-stream 
0097: 
=> Send data, 16384 bytes (0x4000) 
0000: <html> 
... 
... 
13de: </html> 
=> Send data, 452 bytes (0x1c4) 
0000: 
0002: --------------------------18bc7d9c1cff49ca 
002e: Content-Disposition: form-data; name="name" 
005b: 
005d: uploadfile 
0069: --------------------------18bc7d9c1cff49ca 
0095: Content-Disposition: form-data; name="filename" 
00c6: 
00c8: index.htm 
00d3: --------------------------18bc7d9c1cff49ca 
00ff: Content-Disposition: form-data; name="path" 
012c: 
012e:/
0131: --------------------------18bc7d9c1cff49ca 
015d: Content-Disposition: form-data; name="submit" 
018c: 
018e: upload 
0196: --------------------------18bc7d9c1cff49ca-- 

但我需要「文件部分」內的值,因爲在另一邊的嵌入式系統。當我這樣做時,我最終得到一個名爲index.htm並且內容爲index.htm但真實內容除外的文件!這是因爲嵌入式設備上的Fileupload實現。而且我沒有辦法阻止這一點。

設置文件內部值:

捲曲-v -X POST -H 「期望值:」 -F「[email protected];名稱= uploadfile;文件名= index.htm的「-F path =/-F submit = upload http://%url%/cgi-bin/fs_fileupload.cgi --trace-ascii/dev/stdout

這給了我一個捲曲方面的警告。而且它也不適用於嵌入式系統,因爲缺少所需的值。

Warning: skip unknown form field: name=uploadfile 

更多輸出

== Info: Trying 192.168.1.72... 
== Info: TCP_NODELAY set 
== Info: Connected to 192.168.1.72 (192.168.1.72) port 80 (#0) 
=> Send header, 211 bytes (0xd3) 
0000: POST /cgi-bin/fs_fileupload.cgi HTTP/1.1 
002a: Host: 192.168.1.72 
003e: User-Agent: curl/7.54.0 
0057: Accept: */* 
0064: Content-Length: 21875 
007b: Content-Type: multipart/form-data; boundary=-------------------- 
00bb: ----07d21aa34b954425 
00d1: 
=> Send data, 153 bytes (0x99) 
0000: --------------------------07d21aa34b954425 
002c: Content-Disposition: form-data; name="file"; filename="index.htm 
006c: " 
006f: Content-Type: application/octet-stream 
0097: 
=> Send data, 16384 bytes (0x4000) 
0000: <html> 
... 
... 
13de: </html> 
=> Send data, 243 bytes (0xf3) 
0000: 
0002: --------------------------07d21aa34b954425 
002e: Content-Disposition: form-data; name="path" 
005b: 
005d:/
0060: --------------------------07d21aa34b954425  
008c: Content-Disposition: form-data; name="submit" 
00bb: 
00bd: upload 
00c5: --------------------------07d21aa34b954425-- 
== Info: Recv failure: Connection was reset 
== Info: stopped the pause stream! 
== Info: Closing connection 0 
curl: (56) Recv failure: Connection was reset 

這是行不通的。 Curl告訴我,它無法識別我輸入的值。它在嵌入式方面不起作用。連接因缺少值而重新設置!

回答

0

好的,我找到了一個簡單的解決方案。我不確定爲什麼我沒有這樣做,首先...

curl -X POST -H「Expect:」-F「[email protected]/index.htm; filename = index.htm的;」 -F路徑=/-F提交=上傳http://%url%/cgi-bin/fs_fileupload.cgi

與上傳多形式的數據看起來如預期

=> Send data, 159 bytes (0x9f) 
0000: --------------------------5621ade8c7849eac 
002c: Content-Disposition: form-data; name="uploadfile"; filename="ind 
006c: ex.htm" 
0075: Content-Type: application/octet-stream 
009d: 
=> Send data, 16384 bytes (0x4000) 
0000: <html>