我想使用 Electron 向使用 Yii2 构建的 API 发出 API(获取和发布)请求。我尝试过 Axion、Fetch、HTTP、请求模块,它们都给了我同样的错误:
data: { name: 'PHP Notice', message: 'Undefined index: username', code: 8, type: 'yii\base\ErrorException', file: 'C:\xampp\htdocs\app\controllers\ApiController.php ',行:898,'堆栈跟踪':[数组] }
这是我要调用的操作的代码:
public function actionLogin(){
if(Yii::$app->request->isPost){
Yii::$app->response->format = Response::FORMAT_JSON;
$data = Yii::$app->request->post();
$username = $data['username'];
$password = $data['password'];
$device_token = $data['device_token'];
$prefix = substr($username, 0, 3);
$model = null;
}
}
这是 Electron 中的代码:
axios.post('http://localhost:8080/app/api/login', {
username: 'Fred',
psssword: 'Flintstone'
})
.then(function (response) {
console.log(response);
});
由于某种原因,参数没有传递给操作。我尝试了很多方法,这个似乎是最简单的。PS我尝试过的所有方式都给出了同样的错误。