2013-08-20 23 views
1

我需要發送以下請求,該請求是xml結尾處帶有用戶名和密碼的XML。我能得到這個作爲一個URL工作的時候粘貼到瀏覽器:curl請求 - 在xml之後發佈用戶和密碼時出現無效的xml請求

URL?XML=<>...</>&user=123456&password=123456 

但是當我嘗試創建捲曲調用它說,這是一個無效的XML請求。

我試過在POSTFIELDS中有用戶&密碼。我也嘗試將它們設置爲$ trial ='& user = 123456 & password = 123456'之前的變量,但仍似乎無法使其工作。

$xml = <<<ENDOFXML 
<?xml version="1.0" encoding="UTF-8"?><xmldata>...</xmldata> 
ENDOFXML; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded')); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, 'xml='.urlencode($xml).urlencode('&user=123456&password=123456')); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_close($ch); 

回答

1

這是錯誤的:

curl_setopt($ch, CURLOPT_POSTFIELDS, 'xml='.urlencode($xml).urlencode('&user=123456&password=123456')); 

進行urlencode只是變量名和值(或僅值,如果你知道變量名都OK):

curl_setopt($ch, CURLOPT_POSTFIELDS, 'xml='.urlencode($xml).'&user=' . urlencode('123456').'&password=' . urlencode('123456')); 
+0

嗨馬立克,謝謝爲了如此快速的迴應。已經完全忽略了這一點。非常感謝它現在的作品。 –