2009-09-02 8 views
1

curl lib를 사용하여 PHP로 문제가 발생했습니다. 내가 달성하고자하는 것은 curl로 불리는 두 개의 서로 다른 url로부터 반환 된 xml을 가져 오는 여러 요청을하는 것입니다. 내가 처음 호출 내가 값을 추출 할 수 있도록,하지만 두 번째 전화를 걸 때이 값을 추출 할 수 있지만,이 첫 번째 전화의 값 때PHP Curl 다중 요청 문제

$BROWSER="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 YFF3 Firefox/3.0.1"; 

$ch = curl_init(); 

curl_setopt($ch, CURLOPT_URL,"http://www.wowarmory.com/character-sheet.xml?r=Crushridge&n=Thief"); 

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); 

curl_setopt($ch, CURLOPT_USERAGENT, $BROWSER); 


$result20 = curl_exec($ch); 

curl_close ($ch); 

/** 

I extract the values out of the xml here 

**/ 

$ch = curl_init(); 

curl_setopt($ch, CURLOPT_URL,"http://www.wowarmory.com/character-sheet.xml?r=Ursin&n=Kiona"); 

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); 

curl_setopt($ch, CURLOPT_USERAGENT, $BROWSER); 


$result20 = curl_exec($ch); 

curl_close ($ch); 

/** 

I extract the values out of the xml here 
**/ 

: 여기에 코드입니다.

+0

이 코드 조각은 괜찮은 것 같습니다. 어쩌면 다른 곳에서 실수를 저지르고있는 것일 수 있습니다. –

+0

컬 부분이 괜찮습니까? –

답변

1

이 코드는 정상적으로 작동하며 두 개의 다른 페이지를 반환합니다. 추출은 두 호출 후에 수행 할 수 있으며, 지정하면 나머지 호출은 수행되지 않을 수 있습니까? 그렇다면 $ result20을 두 번 사용하면 일치 할 것입니다.

해당 URL을 브라우저에서 직접로드하는 경우 다른 페이지를 반환합니다 (나를 위해 제공).

0

코드가 저에게 잘 작동합니다. Justin이 제안했듯이 추출한 데이터를 덮어 쓰는 것 같습니다.

적은 코드를 제안해도됩니까? 예 :

$urls = array('http://www.wowarmory.com/character-sheet.xml?r=Crushridge&n=Thief', 
       'http://www.wowarmory.com/character-sheet.xml?r=Ursin&n=Kiona'); 
$browser = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 YFF3 Firefox/3.0.1'; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); 
curl_setopt($ch, CURLOPT_USERAGENT, $browser); 

foreach ($urls as $url) { 
    curl_setopt($ch, CURLOPT_URL, $url); 
    $result20 = curl_exec($ch); 
    // Extract the values out of the xml here (to separate variables). 
} 
curl_close($ch);