2012-12-28 115 views
15

我有一個關於cURL用法的簡單問題。在我的Google搜索或手冊頁中找不到太多內容以獲得明確答案。cURL POST --data-binary vs --form

here談論使用--data--form發送文件/附件。我很想知道主要區別是什麼,在什麼情況下你會選擇--data-binary VS --form

的POST「主體」可以通過任一--data (for application/x-www-form-urlencoded)--form (for multipart/form-data)被髮送:

-F "foo=bar"     # 'foo' value is 'bar' 
-F "foo=<foovalue.txt"  # the specified file is sent as plain text input 
-F "[email protected]"  # the specified file is sent as an attachment 

-d "foo=bar" 
-d "foo=<foovalue.txt" 
-d "[email protected]" 
-d "@entirebody.txt"   # the specified file is used as the POST body 

--data-binary "@binarybody.jpg" 

回答

6

的區別說明如下:HTML 4.01 Specification section on Forms

application/x-www-form-urlencoded是默認內容類型。

內容類型「application/x-www-form-urlencoded」對於大量發送包含非ASCII字符的二進制數據或文本而言效率不高。內容類型「multipart/form-data」應該用於提交包含文件,非ASCII數據和二進制數據的表單。

3

這正是主要區別,數據的類型的東西被髮送到服務器(application/x-www-form-urlencoded VS multipart/form-data

+0

謝謝! 你將使用哪種類型的數據? 所以'form-urlencoded'用於將數據嵌入到請求中,但multipart是不同的? – xbeta