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

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

我收到一個帶有 json 帖子的身份驗證錯誤

我收到一個帶有 json 帖子的身份驗證錯誤

PHP
飲歌長嘯 2022-09-12 09:52:03
我正在嘗試進行身份驗證,我的請求結果被錯誤地返回。請求模型方法: Post, Endpoint: /api/authenticate, 標頭變量: [{“密鑰”:“內容類型”,“值”:“應用程序/json”,“已啟用”:true}], 正文參數: 用戶名: 字符串, 密碼: 字符串, 身份驗證類型: 字符串樣品申請POST /api/authenticate Host: mpop-sit.hepsiburada.comContent-Type: application/json{   "username": "xyz_dev",   "password": "XYZ_dev123!",   "authenticationType": "INTEGRATOR"}請求我已發送$url = 'https://mpop-sit.hepsiburada.com//api/authenticate';$ch = curl_init($url);$header = array(    'Content-Type: application/json',    'Authorization: Bearer '. base64_encode('xyz_dev:XYZ_dev123!:INTEGRATOR'),);curl_setopt($ch, CURLOPT_HTTPHEADER, $header);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);$result = curl_exec($ch);$return=json_decode($result,true);print_r($return);這是返回的查詢和我收到的錯誤的結果。你認為我可能在哪里犯了錯誤?數組 ( [時間戳] => 2020-02-07T09:01:47.426+0000 [狀態] => 500 [錯誤] => 內部服務器錯誤 [異常] => io.jsonwebtoken.格式錯誤的Jwt異常 [消息] = > JWT 字符串必須正好包含 2 個句點字符。找到: 0 [路徑] => //api/身份驗證 )
查看完整描述

3 回答

?
臨摹微笑

TA貢獻1982條經驗 獲得超2個贊

這應該工作正常!我收到訪問被拒絕錯誤,所以,這意味著代碼工作正常。


注意 您可能需要更改為http_build_query($fields)$fields


$url = "https://mpop-sit.hepsiburada.com/api/authenticate/";

$token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; 

$fields = array(

   "username" => "xyz_dev",

   "password" => "XYZ_dev123!"

);


$header = array(

    'Content-Type: application/json',

    'Authorization' => 'Bearer ' . $token,

);


//open curl connection

$ch = curl_init();


//set the url, fields, vars

curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

curl_setopt($ch,CURLOPT_URL, $url);

curl_setopt($ch,CURLOPT_POST, true);

curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($fields));

curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false); // SSL false if not required

curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false); //False if not required

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);


//execute fields

$result = curl_exec($ch);

//return result echo $result; if you need

echo curl_error($ch);

//close curl connection

curl_close($ch);

請讓我知道它是否有效!


更新 :如果你想使用ssl,它可以讓你免受黑客攻擊。


按照此答案中的步驟激活 ssl : https://stackoverflow.com/a/59919558/12232340


查看完整回答
反對 回復 2022-09-12
?
藍山帝景

TA貢獻1843條經驗 獲得超7個贊

2 slashes here, so it does not work:

$url = 'https://mpop-sit.hepsiburada.com//api/authenticate';


查看完整回答
反對 回復 2022-09-12
?
catspeake

TA貢獻1111條經驗 獲得超0個贊

Do you need the authentication header for this endpoint?


Because what the sample request wants you to send the parameters in the request body like this:


$post = [

   'username' => 'xyz_dev',

   'password' => 'XYZ_dev123!',

   'authenticationType' => 'INTEGRATOR'

];


$url = 'https://mpop-sit.hepsiburada.com//api/authenticate';

$ch = curl_init($url);

$header = array('Content-Type: application/json');

curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

$result = curl_exec($ch);

$return=json_decode($result,true);

print_r($return);

So no need fot the header, it would also be created differently.Authentication: Bearer ...


查看完整回答
反對 回復 2022-09-12
  • 3 回答
  • 0 關注
  • 181 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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