angular - Angular 7 http.post 正在向 yii2 API 发送 null
问题描述
我正在尝试将数据从角度提交到 Yii2
这是我的角度服务,我试图通过 POST 发送数据
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http'
@Injectable({
providedIn: 'root'
})
export class SubscribeService {
readonly postURL = "http://localhost/sampleproject/frontend/web/api/subscribe";
constructor(private http:HttpClient) { }
subscribeSubmit(subscriber){
let bodyString = JSON.stringify(subscriber);
let headers = new HttpHeaders({
'Content-Type': 'application/json' });
let options = { headers: headers };
return this.http.post(this.postURL, bodyString, options);
}
}
下面是我actionSubscribe
在yii2中的。受到角度影响的 API
public function actionSubscribe(){
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Allow-Headers: Origin, Methods, Content-Type");
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return $_POST;
}
当我调用 API 并尝试打印 $_POST 时,我得到的结果为null
.
为什么我得到空值。请帮忙!!
解决方案
推荐阅读
- python - 如何填充由多条曲线组成的形状?
- php - codeigniter 单选按钮表单的问题
- python - 可取消和非阻塞延迟
- amazon-web-services - 如何在标题中隐藏授权码?
- botframework - 如何在 Slack 中为 OAuth v2 在 Azure Bot 服务上生成嵌入代码
- javascript - 如何获取输入类型号的值并放入全局变量JS
- mysql - 窗口函数 ROW_NUMBER() 使用变量 RUNNING TOTAL 更改处理 ORDER BY
- css - 如何右对齐 LINQPad 查询结果中的一列?
- github - 我是否为我们的团队正在尝试做的事情正确设置存储库?
- mongodb - Discord.js MongoDB 添加新对象问题