PHP REST Issue

Guys

I have been struggling with this code, am new to PHP, took this code from internet & apparently it does;t seem to be working. Here is my case:

I have a restful web service (java based) running on AWS EC2 instance, I am able to connect, send request & receive response using different clients like Soap UI, Java Client etc. But when I tried the below code snippet it did not work. Tell me what is missing.

<?php ini_set("allow_url_fopen", 1); session_start(); extract($_GET); ini_set( "display_errors", 1); $service_url = '......../v12/stream/hello'; $curl = curl_init($service_url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POST, true); $curl_response = curl_exec($curl); echo '

Response : ' . $curl_response; echo '

Last Error : ' . error_get_last(); if ($curl_response === false) { $info = curl_getinfo($curl); curl_close($curl); die('

error occured during curl exec. Additioanl info: ' . var_export($info)); } curl_close($curl); ?>

Error is as follows:

Last Error : array ( ‘url’ => '…, ‘content_type’ => NULL, ‘http_code’ => 0, ‘header_size’ => 0, ‘request_size’ => 0, ‘filetime’ => -1, ‘ssl_verify_result’ => 0, ‘redirect_count’ => 0, ‘total_time’ => 0, ‘namelookup_time’ => 0.002841, ‘connect_time’ => 0, ‘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 ( ), ‘redirect_url’ => ‘’, )

Looks like the code is not able to connect with the EC2 Instance, any help would be highly appreciated.

PS: I have removed the url from the code, since that is confidential.

Cheers

Wrap your code in a try catch block and see what is happening.

[php]try
{
// code to connect ect.
} catch ( Exception $e){
echo $e->getMessage();
}[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service