測試方法:
http_server.php 文件內容
<?php // use Swoole\Http\Server; // $http = new Server("0.0.0.0",9501); 實例化例子 $http = new swoole_http_server("0.0.0.0",8811); $http->on('request', function ($request, $response) {
print_r($request->get); $response->end("<h1>Hello Swoole. #".rand(1000, 9999)."</h1>");
//如果 需要在響應中顯示 參數 就必須 把數組 轉化為json數組 json_encode $response->end("json_encode($request->get)") }); $http->start();
在linux 環境下運行 curl http://127.0.0.1:8811 ip加端口號
獲取到服務器 響應給客戶端的數據
還有一種用服務器域名訪問
傳遞參數 的情況
服務器顯示數據
如果想把傳遞的參數在服務器中顯示 就必須把參數 加到響應的response 的end函數中
返回的數據 必須是字符串 就必須用 json_encode 轉化一下