获取发送到php dose的邮政正文数据作为null
我实际上尝试了所有显示的解决方案。 我尝试了所有选择 angular2 http post post http post http http post as as n null 还有许多其他相关的帖子,到目前为止,什么都没有。 我有一个主要的React应用程序部署了NPM启动,登录的一部分如下:
export async function loginService(credentials) {
return fetch('http://localhost:3333/mock-server/index.php', {
method: 'POST',
body: JSON.stringify(credentials) //user:"user"
})
.then(
function(data){
if(data.status === 422){
data.json().then(val=>console.log("DEVOLUCION 422: "+JSON.stringify(val)));
return;
}
return data.json();
}
).catch(error=>{
console.error('error! ->', error);
})
}
php文件:
<?php
$headers = apache_request_headers();
header("Access-Control-Allow-Origin: http://localhost:3000");
header("Access-Control-Allow-Methods: HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS");
header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method,Access-Control-Request-Headers, Authorization");
header('Content-Type: application/json');
$method = $_SERVER['REQUEST_METHOD'];
if ($method == "OPTIONS") {
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method,Access-Control-Request-Headers, Authorization");
header("HTTP/1.1 200 OK");
die;
}
$username = $_POST['user'];
this $ username
返回null。我不知道该怎么办,我也尝试将普通的“用户=用户”作为URL的一部分发送,但始终返回null。 值得一提的是我的PHP服务器是VSCODE扩展名为“ PHP服务器”。我直接从PHP目录可执行人员直接尝试过,同样运气。当我尝试使用Postman时,它可以正确返回名称。
I have tried literally everything shown as solution.
I have tried every option in
Angular2 http POST body sent as null
and many other related posts, nothing has worked so far for me.
I have the main react app deployed with npm start and part of the login is as follows:
export async function loginService(credentials) {
return fetch('http://localhost:3333/mock-server/index.php', {
method: 'POST',
body: JSON.stringify(credentials) //user:"user"
})
.then(
function(data){
if(data.status === 422){
data.json().then(val=>console.log("DEVOLUCION 422: "+JSON.stringify(val)));
return;
}
return data.json();
}
).catch(error=>{
console.error('error! ->', error);
})
}
PHP File:
<?php
$headers = apache_request_headers();
header("Access-Control-Allow-Origin: http://localhost:3000");
header("Access-Control-Allow-Methods: HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS");
header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method,Access-Control-Request-Headers, Authorization");
header('Content-Type: application/json');
$method = $_SERVER['REQUEST_METHOD'];
if ($method == "OPTIONS") {
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method,Access-Control-Request-Headers, Authorization");
header("HTTP/1.1 200 OK");
die;
}
$username = $_POST['user'];
This $username
returns null. I don't know what else to do, I have tried sending a plain 'user=user' as part of the url as well, but always, it returns null.
Worth mentioning my php server is the Vscode extension "php server". I tried directly as well directly from php directory executable, with the same luck. When I try with Postman, it returns the name correctly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论