Получение «Ошибка 502 - Bad Gateway» при попытке использовать REST Server в облаке9 - PullRequest
0 голосов
/ 17 октября 2018

У меня на рабочем столе простое работающее клиент-серверное приложение RESTful (XAMPP).

Я недавно перешел на Cloud9.

Но я получаю "Ошибка 502 - Bad Gateway".

Вот структура файла:

my_php
      PHP_Study/
               WebServices/
                           Client/
                                  index.php
                          Server/
                                  index.php

APP_ROOT_PATH имеет значение /home/ubuntu/workspace/PHP_Study.

Это код для 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;
 }

?>

Вот код для 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;
        }
    }
}

?>

Спасибо.

...