簡體   English   中英

使用curl,但是我的數組不會發布,並且content-type標頭不會發送

[英]Using curl, however my array will not post and content-type header does not send

這是我執行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: 

字符集看起來好像有空格,或者是空格,不確定這是在SO中還是在代碼中。

您是否真的需要在該位置周圍添加\\ t和\\ n,否則服務器將不會在乎。

嘗試implode()放置post數組,然后僅發送XML字符串。

沒有明確的答案,但希望朝着正確的方向前進。

讓我們知道你過得如何,祝你好運。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM