如何从命令行使用cURL将XML文件POST到本地服务器http://localhost:8080 ?
我应该使用什么命令?
如何从命令行使用cURL将XML文件POST到本地服务器http://localhost:8080 ?
我应该使用什么命令?
从手册上看,我相信这些就是你要找的机器人
-F/--form <name=content> (HTTP) This lets curl emulate a filled-in form in which a user has pressed the submit button. This causes curl to POST data using the Content-Type multipart/form-data according to RFC2388. This enables uploading of binary files etc. To force the 'content' part to be a file, prefix the file name with an @ sign. Example, to send your password file to the server, where 'password' is the name of the form-field to which /etc/passwd will be the input: curl -F password=@/etc/passwd www.mypasswords.com
在你的例子中,这就像 curl -F file=@/some/file/on/your/local/disk http://localhost:8080
如果该问题与您的其他Hudson问题有关,请使用它们提供的命令。命令行中的XML是这样的:
$ curl -X POST -d '<run>...</run>' \
http://user:pass@myhost:myport/path/of/url
你需要稍微改变一下从文件中读取:
$ curl -X POST -d @myfilename http://user:pass@myhost:myport/path/of/url
阅读手册。后面是-d Parameter的摘要。
-d/--data (HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded. Compare to -F/--form. -d/--data is the same as --data-ascii. To post data purely binary, you should instead use the --data-binary option. To URL-encode the value of a form field you may use --data-urlencode. If any of these options is used more than once on the same command line, the data pieces specified will be merged together with a separating &-symbol. Thus, using '-d name=daniel -d skill=lousy' would generate a post chunk that looks like 'name=daniel&skill=lousy'. If you start the data with the letter @, the rest should be a file name to read the data from, or - if you want curl to read the data from stdin. The contents of the file must already be URL-encoded. Multiple files can also be specified. Posting data from a file named 'foobar' would thus be done with --data @foobar.
使用Jenkins 1.494,我能够在Ubuntu Linux 12.10上使用curl和——form参数将文件发送到作业参数:
curl --form name=myfileparam --form file=@/local/path/to/your/file.xml \
-Fjson='{"parameter": {"name": "myfileparam", "file": "file"}}' \
-Fsubmit=Build \
http://user:password@jenkinsserver/job/jobname/build
在Jenkins服务器上,我配置了一个接受单个参数的作业:名为myfileparam的文件上传参数。
curl调用的第一行使用名为myfileparam的参数构造了一个web表单(与作业中的相同);它的值将是本地文件系统中名为/local/path/to/your/file.txt的文件的内容。符号前缀@告诉curl发送一个本地文件,而不是给定的文件名。
第二行定义了一个与第一行的表单参数匹配的JSON请求:一个名为myfileparam的文件参数。
第三行激活表单的Build按钮。第四行是带有“/build”后缀的作业URL。
如果调用成功,curl返回0。如果不成功,则将来自服务的错误或异常打印到控制台。这个答案很大程度上来自一篇与哈德森有关的旧博客文章,我根据自己的需要对它进行了解构和重新编写。
下面是如何在Windows上使用curl命令行在Windows上POST XML。最好使用batch/。CMD文件:
curl -i -X POST -H "Content-Type: text/xml" -d ^
"^<?xml version=\"1.0\" encoding=\"UTF-8\" ?^> ^
^<Transaction^> ^
^<SomeParam1^>Some-Param-01^</SomeParam1^> ^
^<Password^>SomePassW0rd^</Password^> ^
^<Transaction_Type^>00^</Transaction_Type^> ^
^<CardHoldersName^>John Smith^</CardHoldersName^> ^
^<DollarAmount^>9.97^</DollarAmount^> ^
^<Card_Number^>4111111111111111^</Card_Number^> ^
^<Expiry_Date^>1118^</Expiry_Date^> ^
^<VerificationStr2^>123^</VerificationStr2^> ^
^<CVD_Presence_Ind^>1^</CVD_Presence_Ind^> ^
^<Reference_No^>Some Reference Text^</Reference_No^> ^
^<Client_Email^>john@smith.com^</Client_Email^> ^
^<Client_IP^>123.4.56.7^</Client_IP^> ^
^<Tax1Amount^>^</Tax1Amount^> ^
^<Tax2Amount^>^</Tax2Amount^> ^
^</Transaction^> ^
" "http://localhost:8080"
如果你在Windows上使用curl:
curl -H "Content-Type: application/xml" -d "<?xml version="""1.0""" encoding="""UTF-8""" standalone="""yes"""?><message><sender>Me</sender><content>Hello!</content></message>" http://localhost:8080/webapp/rest/hello
你可以使用选项——data with file。
将xml内容写入名为soap_get.xml的文件,并使用curl命令发送请求:
curl -X POST——header "Content-Type:text/xml;charset=UTF-8"——data @soap_get.xml
如果你有多个头文件,那么你可能想使用以下方法:
curl -X POST --header "Content-Type:application/json" --header "X-Auth:AuthKey" --data @hello.json Your_url
您可以使用该命令:
curl -X POST --header 'Content-Type: multipart/form-data' --header 'Accept: application/json' --header 'Authorization: <<Removed>>' -F file=@"/home/xxx/Desktop/customers.json" 'API_SERVER_URL' -k
Powershell + Curl + Zimbra SOAP API
${my_xml} = @"
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">
<soapenv:Body>
<GetFolderRequest xmlns=\"urn:zimbraMail\">
<folder>
<path>Folder Name</path>
</folder>
</GetFolderRequest>
</soapenv:Body>
</soapenv:Envelope>
"@
${my_curl} = "c:\curl.exe"
${cookie} = "c:\cookie.txt"
${zimbra_soap_url} = "https://zimbra:7071/service/admin/soap"
${curl_getfolder_args} = "-b", "${cookie}",
"--header", "Content-Type: text/xml;charset=UTF-8",
"--silent",
"--data-raw", "${my_xml}",
"--url", "${zimbra_soap_url}"
[xml]${my_response} = & ${my_curl} ${curl_getfolder_args}
${my_response}.Envelope.Body.GetFolderResponse.folder.id