亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

抱歉,您不能作為該用戶使用curl request php 創建帖子

抱歉,您不能作為該用戶使用curl request php 創建帖子

PHP
12345678_0001 2023-08-11 16:16:23
我正在使用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;          }
查看完整描述

1 回答

?
搖曳的薔薇

TA貢獻1793條經驗 獲得超6個贊

我已將以下代碼添加到 htaccess 并添加插件(JSON 基本身份驗證),然后它開始工作

`RewriteCond %{HTTP:授權} ^(.)

RewriteRule ^(.) - [E=HTTP_AUTHORIZATION:%1]

SetEnvIf 授權“(.*)”HTTP_AUTHORIZATION=$1`


查看完整回答
反對 回復 2023-08-11
  • 1 回答
  • 0 關注
  • 125 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號