简体   繁体   中英

How to get data from webhook with content-type: application/x-www-form-urlencoded;charset=UTF-8?

I have setup a webhook in zoho crm but when ever i try to fetch the data with json_decode(file_get_contents("php://input"), true) it is always blank. From the look of the content-type the data is not json, i ahve tried everything and i still can't get the data from the webhook.

Any help is much appreciated.

Capture of HTTP POST Request: 在此处输入图片说明

add_action( 'rest_api_init', 'register_api_hooks' );

function register_api_hooks() {
    register_rest_route( 'ep-to-zoho-crm/v1', '/updatecompany', array(
        'methods'  => 'POST',
        'callback' => 'webhook_listener',
    ));
};

function webhook_listener($request){
    // We don't want to process if it did not come from webhook
    //if( !isset( $_GET['companyid'] ) ) { return; }

    //$data = $request->get_param( 'companyid' );

    if ( isset( $_REQUEST['companyid'] ) ) {
        file_put_contents(plugin_dir_path( __FILE__ ).'crm.txt', 'works');
    }else{
        file_put_contents(plugin_dir_path( __FILE__ ).'invalid.txt', 'invalid');
    } 

    /*$data = $_POST['companyid'];

    file_put_contents(plugin_dir_path( __FILE__ ).'crm.txt', $data);


    $json_string = json_encode($_POST);

    $save = file_put_contents(plugin_dir_path( __FILE__ ).'crm.json', $json_string);*/
}
add_action( 'init', 'webhook_listener' );

and then my webhook url looks like this https://example.com/wp-json/ep-to-zoho-crm/v1/updatecompany

这个问题是我的服务器配置不正确,因此数据在发送到我的 webhook url 时被阻止。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM