我的网络服务器有一个非常奇怪的问题。我的服务器为 file_get_contents('php://input') 显示一个空字符串,但只有一个用户。它对我和其他一些人来说很好用,但是一个特定的用户不能在使用 POST 请求的站点上使用任何东西,因为服务器只是在他的 PC 上没有从他的浏览器接收到任何 POST 信息。然而,它在他的手机上也能正常工作。测试更加困难,因为我无法自己复制它,它对我来说效果很好。我让他尝试了多种不同的浏览器并隐身,以防 Chrome 中有一些奇怪的设置破坏了他,但似乎没有任何效果。我已经检查了他的 chrome 工具中的标题,似乎所有信息都在那里,但服务器仍然什么也没看到。我使用的代码非常简单,
let fetchCheckoutID = fetch("stripe/createcustomcheckout.php", {
credentials: 'include',
method: "POST",
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
currency: customCheckoutCurrency.value.toLowerCase(),
price: customCheckoutValue.value,
name: customCheckoutName.value
})
}).then(function (response) {
return response.json();
}).then(async function (session) {
stripe.redirectToCheckout({ sessionId: session.id});
}).then(function (result) {
if(result.error) {
alert(result.error.message);
}
}).catch(function (error) {
console.error("Stripe Setup: ", error);
});
Run Code Online (Sandbox Code Playgroud)
然后在服务器端
$json = file_get_contents('php://input');
$data = json_decode($json);
Run Code Online (Sandbox Code Playgroud)
这只是我发现问题的代码,整个网站上的 POST 请求都没有专门为他工作,但对其他人来说都很好。在过去的 4 个小时里,我一直在和他一起试图解决这个问题,因为几个月来它一直在为他工作,现在突然间他基本上无法使用该站点,因为它依赖于对服务器的 POST 请求。如果这是他可以解决的问题,那么其他用户肯定会遇到同样的问题......我不知道还能去哪里,我找不到任何其他有同样问题的帖子。我只是发现很多人在 $_POST 中找不到信息,人们建议他们使用 file_get_input() …