2013-02-13 3 views
0

API에 대한 표준 HTTP 호출을하는 웹 사이트를 구축 중입니다. 내 첫 번째 호출은 기본 인증을 사용하는 매개 변수가없는 간단한 GET입니다. 내 PHP에서 컬을 사용하고 있습니다. 나는 XAMPP의 로컬 설치를 통해이를 실행하고있다. 내 전화가 작동하지 않습니다하지만 동료가 우분투 PHP의 이전 버전을 실행하는 그의 리눅스 상자에서 PHP를 실행하면 잘 작동합니다. 이 문제를 해결하는 가장 좋은 방법은 무엇입니까? 내 생각 엔 내 XAMPP가 설치되어 있지만 문제 해결을위한 좋은 방법이 있습니까? Curl 세션에서 curl_getinfo를 사용하여 반환 값을 얻었습니다. 그리고 말할 수있는 한 많은 통찰력을 제공하지는 않습니다.PHP Curl GET 통화 문제 해결

Array ( 
[url] => https://www.ebusservices.net/webservices/hrpcertws/rbs/api/merchants/267811683882/consumers.xml? 
[content_type] => 
[http_code] => 0 
[header_size] => 0 
[request_size] => 107 
[filetime] => -1 
[ssl_verify_result] => 0 
[redirect_count] => 0 
[total_time] => 0.28 
[namelookup_time] => 0.015 
[connect_time] => 0.015 
[pretransfer_time] => 0 
[size_upload] => 0 
[size_download] => 0 
[speed_download] => 0 
[speed_upload] => 0 
[download_content_length] => -1 
[upload_content_length] => -1 
[starttransfer_time] => 0 
[redirect_time] => 0 
[certinfo] => Array () 
[primary_ip] => 127.0.0.1 
[primary_port] => 8888 
[local_ip] => 127.0.0.1 
[local_port] => 59509 
[redirect_url] => 
) 

내가 사용하고 : : 여기

이 curl_getinfo의 출력 윈도우 7

추가 된
XAMPP 1.8.1
PHP 버전 5.4.7
컬 7.24.0
코드 :

<?php 

    error_reporting(E_ALL); 

    $session = 'FALSE'; 
    // Initialize the session 
    $session = curl_init(); 

    $stderr = fopen("curl.txt", "w+"); 

    // Set curl options 
    curl_setopt($session,  CURLOPT_URL, 'https://www.ebusservices.net/webservices/hrpcertws/rbs/api/merchants/12233442/consumers.xml?'); 
    curl_setopt($session, CURLOPT_STDERR, $stderr); 
    curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
    curl_setopt($session, CURLOPT_USERPWD, "username:pwd"); 
    curl_setopt($session, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($session, CURLOPT_SSLVERSION, 3); 
    curl_setopt($session, CURLOPT_VERBOSE, 1); 

    // Make the request 
    $response = curl_exec($session); 

    print_r(curl_getinfo($session)); 

    // Close the curl session 
    curl_close($session); 

    fclose($stderr); 

    // Get HTTP Status code from the response 
    $status_code = array(); 
    preg_match('/\d\d\d/', $response, $status_code); 

    // Check the HTTP Status code 
    if(isset($status_code[0])) 
    { 
     switch($status_code[0]) 
    { 
      case 100: 
        break; 
      case 200: 
        break; 
      case 503: 
        die('Your call to HRP API failed and returned an HTTP status of 503. That means: Service unavailable. An internal problem prevented us from returning data to you.'); 
        break; 
      case 403: 
        die('Your call to HRP API failed and returned an HTTP status of 403. That means: Forbidden. You do not have permission to access this resource, or are over your rate limit.'); 
        break; 
      case 400: 
        die('Your call to HRP API failed and returned an HTTP status of 400. That means: Bad request. The parameters passed to the service did not match as expected. The exact error is returned in the XML response.'); 
        break; 
      case 401: 
        die('Your call to HRP API failed and returned an HTTP status of 401. That means: Unauthorized. The credentials supplied do not have permission to access this resource.'); 
        break; 
      case 404: 
        die('Page not found.'); 
        break; 
      default: 
        die('Your call to HRP API returned an unexpected HTTP status of:' . $status_code[0]); 
     } 
    } 
    else 
    { 
     echo 'failed'; 
    } 

    // Get the XML from the response, bypassing the header 
    if (!($xml = strstr($response, '<?xml'))) { 
     $xml = null; 
     //echo 'in xml'; 
    } 

    // Output the XML 
    echo htmlspecialchars($xml, ENT_QUOTES); 

?> 
+0

verbose 옵션을 추가하고 출력이 명령 줄 중 하나인지 확인하십시오. 그리고 몇 가지 코드를 보여줘야합니다. –

+0

수신 페이지에'php_info()'를 실행시키고 반환 된 정보를 확인하십시오. –

+0

XAMPP 외부의 컬 명령 행에서 GET을 실행할 수 있으며 정상적으로 작동합니다. xampp 내에서 같은 컬을 사용하여 컬 명령 행을 실행하는 방법이 있습니까? 나는 그것이 가능하다는 것을 몰랐다. – user1757986

답변

0

Fiddler을 사용하여 HTTP 트래픽의 내용을 정확히보십시오.

+0

나는 Fiddler를 사용했지만 기본 항목은 "www.ebusservices.net:443"의 초기 URL 인 "CONNECT"입니다. 다른 항목이 없습니다. 그 TextView는 clienthello 핸드 셰이크가 발견되었고 "인식 할 수없는 암호"라는 암호 내에 몇 가지 항목을 보았습니다. 가능한 인증서 문제를 지적합니까? 나는 cURL 커맨드 라인과 SoapUI를 통해이 GET을 성공적으로 처리 할 수 ​​있기 때문에 그렇게 생각하지 않을 것이다. – user1757986

+0

나는 실제로 무슨 일이 일어나는지 말할 수 있기 전에 Fiddler 결과를 봐야 할 것입니다. –