Answer the question
In order to leave comments, you need to log in
What am I doing wrong with rest and post request?
I configure the rest like this
config
[
'class' => 'yii\rest\UrlRule',
'controller' => 'v1/bonus',
'extraPatterns' => [
'POST bonus'=>'get-bonus'
],
],
public function actionGetBonus(){
$request = Yii::$app->request->post();
$user=User::findOne(['ref'=>$request['ref']]);
return [
'full_bonus'=>$user->user_bonus,
'frozen'=>$user->frozen,
'bonus'=>($user->user_bonus-$user->frozen)
];
}
$client = new Client();
$response = $client->createRequest()
->setMethod('post')
->setUrl(\Yii::$app->params['bunusapi'])
->setData(['ref' => $userCode])
->send();
if ($response->isOk) {
$newUserId = $response->data['id'];
} else {
return $response;
}
}
object(yii\httpclient\Response)[181]
public 'client' =>
...
public 'contentLoggingMaxSize' => int 2000
...
private '_content' (yii\httpclient\Message) => string '{
"name": "Unauthorized",
"message": "Your request was made with invalid credentials.",
"code": 0,
"status": 401,
"type": "yii\\web\\UnauthorizedHttpException"
}' (length=181)
...
Answer the question
In order to leave comments, you need to log in
The problem is that you are trying to make a request without logging in. Accordingly, it is necessary to carry out the authentication process
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question