2010-07-17 77 views
0

我有一個腳本,使用cURL將數據發送到服務器。當我使用一個HTML表單張貼同樣的數據,在POST看起來是這樣的,一切都很好:使用cURL上傳文件內容

description=Something&name=aName&xml=wholeBiunchOfData&xslt=moreData 

的XML和XSLT大而發生變化;我寧願將它們保存在外部文件中。但是,以下情況並不像我預期的那樣有效;

curl --cookie cjar --cookie-jar cjar --location --output NUL^
--data "name=aName&description=Something"^
    --data "[email protected]"^
--data "[email protected]"^
http://someUrl.html 

我嘗試過@和本地文件的各種組合,但沒有成功。如何POST文件的內容?

回答

1

我建議嘗試以下操作:

curl --cookie cjar --cookie-jar cjar --location --output NUL^
--data "name=aName&description=Something"^
    --data-urlencode "[email protected]"^
--data-urlencode "[email protected]"^
http://someUrl.html 

XML(包括樣式表)將需要URL編碼正在取得URL的一部分了。

您還可以使用--trace-ascii -作爲附加參數將輸入和輸出轉儲爲標準輸出以供進一步調試,並且您可以在主要man page上找到更多信息。

希望這會有所幫助!

+0

太棒了!非常感謝! – Upperstage 2010-07-17 14:07:30

2

看看手冊頁,它看起來像--data @file語法不允許變量名,它必須在文件中。 http://paulstimesink.com/2005/06/29/http-post-with-curl/。你也可以嘗試使用反引號

curl --cookie cjar --cookie-jar cjar --location --output NUL^
--data "name=aName&description=Something"^
--data "xml=`cat localFile.xml`"^
--data "xslt=`cat someFile.xml`"^
http://someUrl.html 
+0

感謝您的回答。 – Upperstage 2010-07-17 14:08:23

+0

此答案中的鏈接已損壞。 – 2012-12-03 05:06:23

+0

看起來像是轉移到http://paulstimesink.com/2005/06/29/http-post-with-curl/。 – 2012-12-03 16:59:15