0
我正在向我创建的API端点发送PUT
请求。使用jwt,我可以成功注册并取回令牌。智威汤逊:为什么我总是得到token_not_provided?
使用邮递员,我的请求完美地工作。
我在我的应用程序中使用Guzzle发送PUT
请求。这是什么样子:
$client = new \Guzzle\Http\Client('http://foo.mysite.dev/api/');
$uri = 'user/123';
$post_data = array(
'token' => eyJ0eXAiOiJKV1QiLCJhbGc..., // whole token
'name' => 'Name',
'email' => [email protected],
'suspended' => 1,
);
$data = json_encode($post_data);
$request = $client->put($uri, array(
'content-type' => 'application/json'
));
$request->setBody($data);
$response = $request->send();
$json = $response->json();
} catch (\Exception $e) {
error_log('Error: Could not update user:');
error_log($e->getResponse()->getBody());
}
当我登录的$data
变量,看看它是什么样子,这是返回什么。
error_log(print_r($data, true));
{"token":"eyJ0eXAiOiJKV1QiL...","name":"Name","email":"[email protected]","suspended":1}
Error: Could not suspend user:
{"error":"token_not_provided"}
看起来好像所有数据都正确填充,我不知道系统为什么没有找到令牌。通过Postman运行“相同”查询(作为PUT
)以及相同的参数运行效果很好。
任何建议,非常感谢!