swoole 1.8.4
curl -XPOST -H "Content-Type: application/json; charset=utf-8" "http://127.0.0.1:9502/index.php" -d '{"json":"yes"}'
这个是 var_dump 出来的 request:
object(swoole_http_request)#5 (3) {
["fd"]=>
int(1)
["header"]=>
array(5) {
["user-agent"]=>
string(110) "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.19.1 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2"
["host"]=>
string(14) "127.0.0.1:9502"
["accept"]=>
string(3) "*/*"
["content-type"]=>
string(31) "application/json; charset=utf-8"
["content-length"]=>
string(2) "14"
}
["server"]=>
array(10) {
["request_method"]=>
string(4) "POST"
["request_uri"]=>
string(10) "/index.php"
["path_info"]=>
string(10) "/index.php"
["request_time"]=>
int(1463023932)
["request_time_float"]=>
float(1463023932.4518)
["server_port"]=>
int(9502)
["remote_port"]=>
int(55416)
["remote_addr"]=>
string(9) "127.0.0.1"
["server_protocol"]=>
string(8) "HTTP/1.1"
["server_software"]=>
string(18) "swoole-http-server"
}
}
server 代码:
<?php
$serv = new swoole_http_server("127.0.0.1", 9502);
$serv->on('Request', function($request, $response) {
var_dump($request);
$response->end("<h1>Hello Swoole!</h1>");
});
$serv->start();
?>
使用$req->rawContent() 得到请求的内容。
使用
$req->rawContent()得到请求的内容。
谢谢!
Most helpful comment
使用
$req->rawContent()得到请求的内容。