php
  • web-services
  • curl
  • 2013-06-17 2 views 0 likes 
    0

    I 컬을 사용하여, PHP에서 웹 서비스를 호출하기 위해 다음과 같은 코드가 있습니다PHP CURL 웹 서비스 호출

    <?php 
    echo "Init<br />"; 
    $url = 'http://server-ip/applications/time2gate.aspx?x=1182&y=365&map=1002&gate=B3&mode=time2gate&session=5fdf288d-01b0-414a-ba2a-58d3f624e453'; 
    
    $ch = curl_init($url); 
    echo "1"; 
    curl_setopt($ch, CURLOPT_HEADER, false); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    $resp = curl_exec($ch); 
    
    $status_code = array(); 
    preg_match('/\d\d\d/', $resp, $status_code); 
    
    switch($status_code[0]) { 
         case 200: 
          echo "Success<br />"; 
          break; 
        case 503: 
          die('Your call to Web Service failed and returned an HTTP 503.'); 
          break; 
        case 403: 
          die('Your call to Web Service failed and returned an HTTP status of 403.'); 
          break; 
        case 400: 
          die('Your call to Web Services failed and returned an HTTP status of 400.'); 
          break; 
        default: 
          die('Your call to Web Services returned an unexpected HTTP status of:' . $status_code[0]); 
    } 
    
    if(curl_errno($ch)) 
    { 
        echo 'error' . curl_error($ch); 
    } 
    
    curl_close($ch); 
    
    ?> 
    

    문제는 내가 163, 815, 329과 같은 HTTP 응답 코드를받을 수입니다 .. 왜 이런 일이 일어나는거야? 이 코드들은 무엇을 의미합니까? 나는 아파치의 오류 로그를 점검했고 코드에 어떤 오류도 보지 못했다. 또한 제공된 URL에 대한 호출을 테스트했으며 Mozilla의 Poster Add-on에서 작동합니다.

    아이디어가 있으십니까? https://github.com/rmccue/Requests

    내가 넣어했습니다 내가 GitHub의에서 사용할 수있는 간단한 라이브러리를 사용하는 API 호출을 할 필요가있을 때 나는 우분투, PHP 5 함께 일하고

    12. 닉

    +0

    정말 HTTP 응답 코드입니까? http://en.wikipedia.org/wiki/List_of_HTTP_status_codes 그들은 익숙하지 않다. – ajtrichards

    +0

    글쎄, 나는 http://developer.yahoo.com/php/howto-reqRestPhp.html에서 지시를 따랐다. HTTP 응답 코드를 확인하는 또 다른 방법이 있습니까? –

    +1

    아마도 서비스 호출의 실제 결과가 없으면 얻으려고하는 가장 좋은 대답은 당연한 것입니다. – Crontab

    답변

    1

    을 주셔서 감사합니다 이 라이브러리를 사용하는 아래 예제에서는 API의 전체 응답을 인쇄합니다.

    <?php 
    
    require_once('library/Requests.php'); 
    
    $url = 'http://server-ip/applications/time2gate.aspx?x=1182&y=365&map=1002&gate=B3&mode=time2gate&session=5fdf288d-01b0-414a-ba2a-58d3f624e453'; 
    
    // Next, make sure Requests can load internal classes 
    Requests::register_autoloader(); 
    
    // Now let's make a request! 
    $request = Requests::get($url, array('Accept' => 'application/json')); 
    
    echo '<pre>'; 
        print_r($request); 
    echo '</pre>'; 
    
    +0

    답변 해 주셔서 감사합니다.하지만 저는 순수한 PHP 컬 서비스 요청에 충실하고 싶습니다. –

    관련 문제