wget -d --header="Content-Type:application/xml" --post-data="$(cat <your xml file>)" http://sample.sample.com/api
如何在php中使用此函數? 我也想得到這個函數的響應。 我在PHP中可行的一個變量是這樣如何將此wget函數轉換爲php?
$xml = '<sample>
<Request target="test">
</Request>
</sample>'
這是我要發佈的XML。
我試過如下:
$url = 'sample.sample.com/api';;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "$(cat <".$xml.">)"); // receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo $server_output = curl_exec ($ch);
curl_close ($ch);
但它返回此錯誤:
Parsing XML failed: Start tag expected, '<' not found
你試過PHP捲曲對象? – georgecj11 2013-03-23 14:13:29
我不知道如何使用捲曲功能像這樣的wget功能......如果你知道如何使捲曲這樣工作,它將是偉大的 – 2013-03-23 14:15:40
這個問題的重複:http://stackoverflow.com/questions/3080146/post -data-to-url-php – 2013-03-23 14:16:56