2010-07-17 75 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