2012-06-25 12 views
0

這是我執行的POST代碼:,但是我的數組將不會發布和Content-Type頭不發送

$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: 
+0

你能發佈像這個URL中指定的$數據,並檢查一次http://davidwalsh.name/execute-http-post-php-curl – MMK

+0

Erm ...你爲什麼發送一個XML塊而不是發送它只是在一個參數? 400錯誤通常是由於不遵循URL所有者設置的一些規則而導致的。 – raina77ow

回答

0

的字符集看起來有空格或其他東西,不知道這是否正在進入SO或實際在您的代碼中。

你真的需要在地方附近添加\ t和\ n,如果你不這樣做,服務器不會在意。

嘗試implode()ing數組,然後發送一個XML字符串。

沒有明確的答案,但希望在正確的方向。

讓我們知道你如何繼續,祝你好運。