0

我将一些 XML 发布到 web 服务,我编写的代码在所有其他情况下都有效,只是在这种情况下无效。

这是我的代码;

$ch = curl_init(); 

curl_setopt($ch, CURLOPT_POSTFIELDS, $string);  
curl_setopt($ch, CURLOPT_ENCODING,'gzip');
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_TIMEOUT, 45); 
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml")); 

$result = curl_exec($ch); 

curl_close($ch);

return $result;

它不断返回 500 内部服务器错误,这与您直接访问 url 相同,因此就像未发送 POST 数据一样。但我没有检查内容长度,它似乎是..

有任何想法吗?

4

1 回答 1

0

试试这个

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_string); // NOTE used $xml_string to indicate its just a text string of XML format
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_NOPROGRESS, 0);

    $result = curl_exec($ch);
    curl_close($ch);
于 2012-07-25T15:57:37.980 回答