我在前端应用程序中使用Axios和React。当我尝试使用Axios(xhr,fetch)通过HTTPS发送POST请求并遇到奇怪的问题时,我的POST请求在Edge开发工具中变成了GET。
这是我的要求:
public function getFamilyAttribute()
{
$family = collect([]);
$children = $this->children;
while (!is_null($children )) {
$family->push($children);
$children = $children->children;
}
return $family;
}
然后,我尝试挖掘北斗-创建了一个简单的HTTPS服务器,并尝试从客户端发送POST请求。
const response = await axios.post(
config.local + "/api/login/credentials",
{
login,
password
}
);
然后,据我了解,该请求未到达服务器。
以下是一些链接:
答案 0 :(得分:0)
控制台中是否有任何错误?您可以使用Fiddler来跟踪网络流量并查看详细信息。您提供的第一个链接中也提到了这一点,您也可以在GitHub链接中尝试两种解决方案:
我的问题是由HTTPS引起的;当我从前端发送HTTP帖子时,后端需要HTTPS。现在,我将两者都更改为HTTPS。
我通过使用“ URLSearchParams”类以另一种格式传递数据来解决了该问题。 我也有同样的问题: 微软Edge 44.18362.267.0 微软EdgeHTML 18.18362 Windows 10
我认为问题在于Edge在发布请求中仅支持某些数据类型。如果要使用内容类型“ application / x-www-form-urlencoded”,请使用URLSearchParams使其在Edge和其他浏览器(如Firefox和Chrome)中运行。即使在其他浏览器中,传递查询字符串在Edge中似乎也不起作用。
修改原始帖子源代码,结果将是:
import Axios from 'axios' import Promise from 'es6-promise' Promise.polyfill() const URL= 'http://192.168.0.112/account/login/username' // Use URLSearchParams instead: const dataParams = new URLSearchParams() dataParams.append('username', 'admin') dataParams.append('password', 'admin') Axios.post(URL, dataParams, { // if you still have problems try more specific options like: // withCredentials: true, // crossdomain: true, // ... }) .then(res=>{ console.log(res) } ) .catch(error=>{ console.log(error) } )
除此之外,您问题中的问题通常是由 CORS 引起的。如果您使用CORS并请求不受信任的来源,则Microsoft Edge将仅发送GET
请求,并导致其他请求失败。您也可以参考this thread来了解为什么CORS请求在Microsoft Edge中失败而在其他浏览器中可以工作。 Microsoft Edge还使用Enhanced Protected Mode,其结果是:如果该站点是受信任的,它将发出两个请求,OPTIONS
和GET
,但是,如果该站点不受信任,则仅发出{ {1}}个导致失败的请求。
答案 1 :(得分:0)
在我的情况下,问题是由自签名证书引起的。我一开始使用普通证书,一切就开始起作用。