这是我执行 POST 的代码:
$url = "http://www.xxxxxxxxxxx.com/dfeed/index.cfm"; //where to send it
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1); // set url to post to
curl_setopt($ch, CURLOPT_URL, $url); // set url to post to
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=ISO- 8859-1'));
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 40); // times out after 4s
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // add POST fields
curl_setopt($ch, CURLOPT_POST, 1);
$result = curl_exec($ch); // run the whole process
echo $result;
//echo curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
我的帖子数组以相同的几个(手动定义)条目开始,如下所示:
$data[0] = "<?xml version='1.0' encoding='ISO-8859-1'?>\n";
$data[1] = "<rss xmlns:g='http://base.google.com/ns/1.0' version='2.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:noNamespaceSchemaLocation='http://www.xxxxx.com/dFeed/schemas/FeedSchema1.0.xsd'>\n";
其余的填充在这样的循环中:
array_push($data, "\t<item>\n");
服务器的响应表明与我设置的内容类型不同,并且还表明它没有收到任何信息,所以一定有问题:
HTTP/1.1 400 Bad Request Transfer-Encoding: chunked Content-Type: text/htmlServer: Microsoft-IIS/7.0 X-XXX Server: Web2 Date: Mon, 25 Jun 2012 12:49:53 GMT Bad Request
Error: Not XML
Content received: