2016-08-19 5 views
0

내가 만든 API 끝점에 PUT 요청을 보냅니다. jwt를 사용하여 토큰을 성공적으로 등록하고 가져올 수 있습니다.JWT : 나는 왜 항상 token_not_provided를 얻고 있습니까?

우편 배달부를 사용하여 나의 요청은 완벽하게 작동합니다.

신청서에 Guzzle을 사용하여 PUT 요청을 보내고 있습니다. 이 반환되는 것입니다, 내가 어떻게 생겼는지 볼 수 $data 변수를 로그인 할 때

$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());    
} 

이는 모습입니다.

error_log(print_r($data, true)); 

{"token":"eyJ0eXAiOiJKV1QiL...","name":"Name","email":"[email protected]","suspended":1} 

Error: Could not suspend user: 
{"error":"token_not_provided"} 

모든 데이터가 올바르게 채워지는 것처럼 보입니다. 시스템이 토큰을 찾지 못하는 이유가 확실하지 않습니다. 같은 매개 변수와 함께 우편 배달부 (PUT)를 통해 "동일한"쿼리를 실행하면 효과가 있습니다.

모든 의견을 매우 높이 평가합니다.

답변

0

토큰이 아닌 게시물 데이터 파라미터

$request->addHeader('Authorization', 'Basic eyJ0eXAiOiJKV1QiL...'); 
같이, 인증 헤더에 설정해야