I have a simple working RESTful client/server application on my desktop(XAMPP).
I recently moved to Cloud9.
But I am getting "Error 502- Bad Gateway".
Here is the file structure:
my_php
PHP_Study/
WebServices/
Client/
index.php
Server/
index.php
APP_ROOT_PATH is set to /home/ubuntu/workspace/PHP_Study.
This is the code for Client/index.php
<html>
<body>
<form method="POST" action="" >
<input type="text" name="name" >
</br>
<input type="submit" name="submit">
</form>
</body>
</html>
<?php
if ( isset( $_POST['submit'] ) )
{
//echo "I am inside <br>";
$RootPath = getenv('APP_ROOT_PATH');
echo 'RootPath = ' . $RootPath . '<br>';
$name = $_POST['name'];
//$url = "https://my-php-dguai.c9users.io/PHP_Study/WebServices/?book=$name";
//$url = "https://my-php-dguai.c9users.io/my_php/PHP_Study/WebServices/?book=$name";
//$url = "https://my-php-dguai.c9users.io/WebServices/Server/?book=$name";
//$url = "https://my-php-dguai.c9users.io/my_php/PHP_Study/WebServices/Server/Index.php?book=$name";
//$url = "https://ide.c9.io/dguai/my_php/PHP_Study/WebServices/Server/Index.php?book=$name";
//$url = "https://dguai-my-php-3600949:8080/ide.c9.io/dguai/my_php/PHP_Study/WebServices/Server/Index.php?book=$name";
$url = "https://dguai-my-php-3600949:8080/WebServices/Server/Index.php?book=$name";
$client = curl_init( $url );
curl_setopt( $client, CURLOPT_RETURNTRANSFER, 1 );
$response = curl_exec( $client );
var_dump($response);
//echo $response;
$output = json_decode( $response );
echo "It is listed $" . $output->data;
}
?>
Here is code for Server/index.php
include "functions.php";
if( !empty( $_GET['book'] ) )
{
$price = getPrice( $_GET['book'] );
if( empty( $price ) )
{
deliver_response( 200, "Book NOT found", NULL );
}
else
{
deliver_response( 200, "Book found", $price );
}
}
else
{
deliver_response( 400, "Input missing", NULL );
}
function deliver_response( $status, $status_message, $data )
{
header( "HTTP/1.1 $status $status_message" );
$response['status'] = $status;
$response['status_message'] = $status_message;
$response['data'] = $data;
$json_response = json_encode( $response );
echo $json_response;
}
?>
Server/functions.php
function getPrice( $findBook )
{
$Books = array(
"Java" => 30,
"C" => 25,
"PHP" => 40,
);
foreach( $Books as $Book=>$Price )
{
if( $findBook == $Book )
{
return $Price;
return;
}
}
}
?>
Thank you.