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