尝试在cloud9中使用REST Server时出现“错误502-错误的网关”

时间:2018-10-17 04:48:53

标签: php rest cloud9

我在桌面(XAMPP)上有一个简单的RESTful客户端/服务器应用程序。

我最近搬到了Cloud9。

但是我收到“错误502-错误的网关”消息。

这是文件结构:

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;
        }
    }
}

?>

谢谢。

0 个答案:

没有答案