The Response content must be a string or object implementing __toString(), “boolean“ given

如果传入的值没有问题那么就是连接工具的问题了。我用的是php的curl,需要做一些封装。需要添加一个header.

function postCurl($url,$data,$type)

    {
    
    

        if($type == 'json'){
    
    

            $data = json_encode($data);//对数组进行json编码

            $header= array("Content-type: application/json;charset=UTF-8","Accept: application/json","Cache-Control: no-cache", "Pragma: no-cache");

        }

        $curl = curl_init();

        curl_setopt($curl,CURLOPT_URL,$url);

        curl_setopt($curl,CURLOPT_POST,1);

        curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);

        curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,false);

        if(!empty($data)){
    
    

            curl_setopt($curl,CURLOPT_POSTFIELDS,$data);

        }

        curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);

        curl_setopt($curl,CURLOPT_HTTPHEADER,$header);

        $res = curl_exec($curl);

        if(curl_errno($curl)){
    
    

            echo 'Error+'.curl_error($curl);

        }

        curl_close($curl);

        return $res;

    }

猜你喜欢

转载自blog.csdn.net/weixin_41429587/article/details/116456139