0

I have the following code in order to call a Web Service from php, using 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);

?>

The problem is that I receive HTTP response codes like 163, 815, 329... Why is this happening? What do these codes mean? I checked Apache's error log and I have not seen any errors on my code. Also, I tested a call to the url provided and it works with Mozilla's Poster Add-on.

Any ideas? I am working with php 5, on Ubuntu 12.

Thank you, Nick

4
  • Are you sure they are HTTP response codes? en.wikipedia.org/wiki/List_of_HTTP_status_codes They don't look familiar Commented Jun 17, 2013 at 14:49
  • Well I followed the instructions from developer.yahoo.com/php/howto-reqRestPhp.html . Is there another way to check the HTTP response code? Commented Jun 17, 2013 at 14:53
  • 1
    Probably, but without the actual output from the service call the best answer you're going to get is a wild guess. Commented Jun 17, 2013 at 14:54
  • How can I print the actual output from the service call then? Commented Jun 17, 2013 at 14:55

1 Answer 1

1

When I need to make API calls I use a simple library available on GitHub: https://github.com/rmccue/Requests

I've put an example below which uses this library and it will print out the full response from the 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>';
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your response but I want to stick with pure php-curl web service calls.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.