2011-07-21 30 views
0

雖然我將XML內容從一臺服務器發佈到其他服務器,但未添加。 我正在使用cURL將xml文件發佈到另一臺服務器。但我得到如下回應:通過CURL發佈的XML文件沒有達到網址

HTTP/1.1 200 OK 
Date: Thu, 21 Jul 2011 08:13:02 GMT 
Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch mod_ssl/2.2.8 OpenSSL/0.9.8g 
X-Powered-By: PHP/5.2.4-2ubuntu5.6 
Set-Cookie: PHPSESSID=6846cb7e65f6f6d6d87f163a681f0543; path=/ 
Expires: Thu, 19 Nov 1981 08:52:00 GMT 
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 
Pragma: no-cache 
Content-Length: 5721 
Content-Type: text/html; charset=UTF-8 

這是我的代碼

$file_path= WWW_ROOT.$xmlfilename;   
$xmldata = file_get_contents($file_path); 
$request = 'http://www.sample.com/someaction'; 
$postargs = 'xml='.urlencode($xmldata).'&filename='.urlencode($xmlfilename); 

// Get the curl session object 
$session = curl_init($request); 

// Set the POST options. 
curl_setopt($session, CURLOPT_POST, true); 
curl_setopt($session, CURLOPT_POSTFIELDS, $postargs); 
curl_setopt($session, CURLOPT_HEADER, true); 
curl_setopt($session, CURLOPT_RETURNTRANSFER, true); 

// Do the POST and then close the session 
$response = curl_exec($session); 
print_r($response); 

注:於allow_url_fopen和捲曲在兩個服務器上啓用。

回答

2

嘗試這樣分配給它:

$ postargs =陣列( 'XML'=>進行urlencode($ XMLDATA), '文件名'=>進行urlencode($ xmlfilename))

兩個項目應該然後出現在接收端的$ _​​POST ['xml']和$ _POST ['filename']中(或者如果不是PHP的話)。

編輯

OK,你可能需要看流媒體使用CURLOPT_READFUNCTION XML文件。

了一下爲例http://zingaburga.com/2011/02/streaming-post-data-through-php-curl-using-curlopt_readfunction/

+0

的是的,我這樣也..同樣的問題做了見這.....如果我張貼大型內容也可能是這個問題?我也發佈了小內容..但仍然相同 – AnNaMaLaI

+0

好吧,如果它非常大,您可能需要將它流式傳輸......請參閱編輯。 – Brian

+0

是的,現在它的工作正常... :) – AnNaMaLaI