http-client post有问题,请教各位是怎么回事?

veinliu

如题:直接用网上找到PHP代码测试,接口返回结果正常,但用http-client post 之后对方没有得到数据;
我要post 的数据为:

{"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);

这样返回的结果正常。

 $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,从返回的结果看对方接口好像什么数据都没收到。
            都post到自己的测试接口,http://192.168.11.129:2121
            var_dump $_POST
            结果是一样的
            array(1) {
  ["{"way_code":"001","position":"1","RfidNo":"1000000002"}"]=>
  string(0) ""
}

就是没想明白哪里不对了。

2020 1 0
1个回答

walkor

v0.1.2 已经修复

  • veinliu 2019-12-08

    我怎么升级到v0,1,2

  • veinliu 2019-12-08

    您这个响应速度也太快了点!就是能不能给我点积分,我没积分不能发贴和回贴了。

年代过于久远,无法发表回答
🔝