![](/img/trans.png)
[英]file_get_contents(): Content-type not specified assuming application/x-www-form-urlencoded
[英]How to get data from webhook with content-type: application/x-www-form-urlencoded;charset=UTF-8?
我在 zoho crm 中設置了一個 webhook,但是當我嘗試使用json_decode(file_get_contents("php://input"), true)
獲取數據時json_decode(file_get_contents("php://input"), true)
它總是空白。 從內容類型的外觀來看,數據不是 json,我已經嘗試了所有方法,但仍然無法從 webhook 中獲取數據。
任何幫助深表感謝。
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' );
然后我的 webhook url 看起來像這樣https://example.com/wp-json/ep-to-zoho-crm/v1/updatecompany
這個問題是我的服務器配置不正確,因此數據在發送到我的 webhook url 時被阻止。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.