dongle7637 2016-05-04 05:41
浏览 41
已采纳

如何在curl发送的php文件中处理POST

I have created a file on bluehost server test.php and used this file send curl request from another server ( godaddy ).

$url = 'http://dev.testserver.com/test.php';
        $data_string = json_encode($fields);
        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_POST, 1); 
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
        curl_setopt($curl, CURLOPT_POSTFIELDS,$data_string );                                                                  
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);                                                                      
        $curl_response = curl_exec($curl);

How to capture posted data on test.php and process it ? I am trying with $_POST but its showing blank.

  • 写回答

2条回答 默认 最新

  • dongzhukuai8177 2016-05-04 05:58
    关注

    Try to replace this, direct send array not json

    curl_setopt($curl, CURLOPT_POSTFIELDS,$data_string );
    

    With

    curl_setopt($curl, CURLOPT_POSTFIELDS,$fields );
    

    Check this : http://php.net/manual/en/function.curl-setopt.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?