The API method that I call:

public function actionCreate() { $request = Yii::$app->request; $resource = $request->post('resource'); $sourceId = $request->post('sid'); if ($resource && $sourceId) { // Код } else { // Получаю это сообщение throw new HttpException(400, "Check parameters 'resource' (value: $resource) or 'sid' (value: $sourceId)"); } } 

And the code on Angular that I am trying to call:

 var post = function(method, data) { var requestParams = { url: 'api/method', method: 'POST', data: { 'resource': 'asdasd', 'sid': 123 }, headers: { 'Content-Type': 'application/javascript; charset=UTF-8' //'Content-Type': 'application/json; charset=UTF-8' } }; return $http(requestParams); }; var useSource = function(source) { post('sources', { 'resource': source.resourceId, 'sid': source.id }).then(function(response) { console.log('success'); console.log(response); }, function error(response) { console.log('error'); console.log(response); }); } 

I always get this error:

Check parameters 'resource' (value:) or 'sid' (value:)

As if, I do not specify the parameters when querying in the angular.

What could be the problem?

  • check what is sent to you, whether these parameters are in the request, for example, on the browser's Network tab - Grundy

1 answer 1

Try to see the data in the request body.

 $post = file_get_contents('php://input'); 

Also, if you request data crossdomainly (subdomain, another domain), you need to configure the yii2 controller or action to accept such data.