php - 从 Angular 发送到 PHP 的 POST 对象为空,Get 和 Server 正在响应
问题描述
我已经被困在这几天了。我尝试通过 HttpClient 模块从 Angular 使用站点,到目前为止,我已经通过标头传递了 CORS,并且服务器响应了我的请求,但是我需要通过邮寄方式发送数据,如果我打印服务器响应它会打印 GET, REQUEST 和 SERVER 没有问题,但 POST 它作为空对象返回。我已经查看了一些文档并测试了一些配置,但我没有成功。有没有人遇到过类似的情况?
我的帖子数据
postData = {
usuario: 'admin@localhost.com',
password: 'securePassword',
texto: 'This is a Simple Text'
};
我的角函数
testConection(postData) {
this.http.post(
this.url,
postData,
{responseType: 'text'} /* {responseType: 'json'} */
)
.toPromise()
.then(
response => {
console.log(response);
}
);
我的PHP函数代码
public function post()
{
$response['POST'] = $_POST;
$response['GET'] = $_GET;
$response['SERVER'] = $_SERVER;
$response['REQUEST'] = $_REQUEST;
$response['COOKIE'] = $_COOKIE;
$response['ENV'] = $_ENV;
// echo json_encode($response);
print_r($response);
PHP 和 .htaccess 中的标头
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
header("Allow: GET, POST, OPTIONS, PUT, DELETE");
在控制台中响应。 在控制台中响应
解决方案
推荐阅读
- c++ - QT qScriptConnect 不工作
- singularity-container - 错误:在构建奇点容器时,在未初始化的配置子系统上调用了singularity_config_get_value
- python - 将带有注释的签名添加到扩展方法
- reactjs - 构造函数中的数组道具为空
- c# - 我是代表的新手,想知道如何分解以下代码
- ios - iOS应用程序中的WKWebView需要很长时间才能加载
- git - 远程 git 分支未显示在 IDE 中
- mysql - 在两个表之间传输一个值,其中一个字段是 %LIKE% 另一个
- c# - 实体框架中的 Linq group by
- javascript - 什么时候在 Javascript 中使用双重相等(松散相等)有意义?