如題:直接用網(wǎng)上找到PHP代碼測試,接口返回結(jié)果正常,但用http-client post 之后對方?jīng)]有得到數(shù)據(jù);
我要post 的數(shù)據(jù)為:
{"way_code":"001","position":"1","RfidNo":"1000000002"}
function send_post($url, $post_data) {
//$postdata = http_build_query($post_data);
$options = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type:application/x-www-form-urlencoded',
'content' => '{"way_code":"001","position":"1","RfidNo":"1000000002"}',
'timeout' => 15 * 60 // 超時時間(單位:s)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
echo $result;
return $result;
}
send_post('http://192.168.11.129:2121', $post_data);
這樣返回的結(jié)果正常。
$post = '{"way_code":"001","position":"1","RfidNo":"1000000002"}';
// var_dump($post);
$http = new Workerman\Http\Client();
$http->post('http://172.50.10.2:7090/facematch/v1/request', $post, function($response){
// $http->post('http://192.168.11.129:2121', $post, function($response){
// var_dump($response->getStatusCode());
// var_dump($response->getBody());
echo $response->getBody();
return $response->getBody();
}, function($exception){
echo $exception;
});
這樣POST,從返回的結(jié)果看對方接口好像什么數(shù)據(jù)都沒收到。
都post到自己的測試接口,http://192.168.11.129:2121
var_dump $_POST
結(jié)果是一樣的
array(1) {
["{"way_code":"001","position":"1","RfidNo":"1000000002"}"]=>
string(0) ""
}
就是沒想明白哪里不對了。