我正在使用curl請求在wordpress網站上發帖,兩年來一切都工作正常,突然wordpress curl停止工作。1 我更新了 htaccess 并嘗試了所有可能的解決方案,但沒有運氣2 我安裝了 wp 基本身份驗證,但它不起作用3 我安裝了 jwt 身份驗證插件但沒有運氣4 我將每個角色分配給用戶并更新密碼,但不幸的是,wordpress 未驗證遠程請求。5 在郵遞員中顯示“{ "code": "rest_cannot_create", "message": "Sorry, you are not allowed to create posts as this user.", "data": { "status": 401 }}代碼:function do_wordpress_curl($data,$url,$header,$wp_rest_username,$wp_rest_password){ $header_array = array(); $auth = 'Authorization: Basic ' . base64_encode( $wp_rest_username . ':' . $wp_rest_password ); array_push($header_array,$auth); if($header <> null) array_push($header_array,stripslashes($header)); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,$data); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Receive server response ... curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Set Custom headers ... curl_setopt($ch, CURLOPT_HTTPHEADER, $header_array ); $server_output = curl_exec($ch); var_dump($server_output); // die(); $header_data= curl_getinfo($ch); curl_close ($ch); $response = json_decode($server_output, true); return $response; }
抱歉,您不能作為該用戶使用curl request php 創建帖子
12345678_0001
2023-08-11 16:16:23