使用$ curl将响应发送到另一个php文件会返回错误

时间:2018-06-30 14:42:33

标签: php json curl

我现在正尝试将JSON数据发送到另一个php文件中以进行学习(实际上是要发送到react-native应用程序),但这会返回错误信息

  

错误:对URL http://localhost/hhh.php的调用失败,状态为200,响应,curl_error,curl_errno 0

 if($cliSeq==0)
    {
        $welcomearr= array("welcome");
              $url = "http://localhost/hhh.php";   

            $welcomeJSON = json_encode($welcomearr);


             $curl = curl_init($url);
            curl_setopt($curl, CURLOPT_HEADER, false);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl, CURLOPT_HTTPHEADER,
            array("Content-type: application/json"));
            curl_setopt($curl, CURLOPT_POST, true);
            curl_setopt($curl, CURLOPT_POSTFIELDS,  $welcomeJSON);

            $json_response = curl_exec($curl);

            $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

            if ( $status != 201 ) {
                die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
            }


            curl_close($curl);

            $response = json_decode($json_response, true);
}

0 个答案:

没有答案