2012-04-22 12 views
2

curlを使用してXMLファイルをサーバーに送信します。すべてが完璧に動作しますが、レスポンスを最良の方法で処理する方法がわかりません。私はsimpleXMLでそれを解析したいと思います。この要求に:curl POSTレスポンスからXMLを解析する

$ch = curl_init(); 

curl_setopt($ch, CURLOPT_VERBOSE, 1); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); 
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_TIMEOUT, 40); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $XPost); 
curl_setopt($ch, CURLOPT_POST, 1); 

$data = curl_exec($ch); 

if(curl_errno($ch)) 
print curl_error($ch); 
else 
print_r($data); 
curl_close($ch); 

私は、応答文字列(ブラウザのソース表示)としてこれを取得しています

HTTP/1.1 200 OK 
Server: Apache-Coyote/1.1 
Expires: Sat, 6 May 1995 12:00:00 GMT 
Cache-Control: no-store, no-cache, must-revalidate 
Cache-Control: post-check=0, pre-check=0 
Pragma: no-cache 
Set-Cookie: JSESSIONID=5FD40C8D8F5EDC85E57AF39E877BE564; Path=/upp/; Secure; HttpOnly 
Content-Type: text/xml;charset=UTF-8 
Content-Length: 829 
Date: Sun, 22 Apr 2012 08:59:10 GMT 

<?xml version='1.0' encoding='UTF-8'?> 
<authorizationService version='1'> 
<body merchantId='635634545' status='accepted'> 
<transaction refno='1234987' trxStatus='response'> 
    <request> 
    <amount>2000</amount> 
    <currency>USD</currency> 
    </request> 
    <response> 
    <responseCode>01</responseCode> 
    <responseMessage>Authorized</responseMessage> 
    </response> 
</transaction> 

どのように私は正しくsimpleXML.Iと$データを解析ん取り払う意味ヘッダー部分の?

答えて

5

ヘッダーが不要な場合は、CURLOPT_HEADERfalseに設定します。

+0

これだけ簡単です!どうもありがとう。 – lunacafu

関連する問題