为了账号安全,请及时绑定邮箱和手机立即绑定

我收到一个带有 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 关注
  • 293 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号