带有JSON的PHP Curl POST返回服务器错误500 - Django

时间:2016-06-29 08:51:31

标签: json post curl

我使用下面的代码来制作PHP Curl POST请求。有人能告诉我,为什么服务器发给我服务器错误代码500?在浏览器中打开api链接并使用json数据进行测试时一切正常。我使用类似的代码来发出PUT请求,但我没有问题。

            $postArray = array(
                "email" => $email
            );
            $json = json_encode( $postArray, JSON_PRETTY_PRINT );

            $pl4m_url = "api-link";



            $ch = curl_init($pl4m_url);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");  
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS,$json);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
            $result = curl_exec($ch);
            curl_close($ch); 
            echo $result;

0 个答案:

没有答案
相关问题