我正在尝试开发草图插件,我使用官方的SKPM通过Fetch构建了一个简单的请求,但遇到了安全错误:可能未处理的承诺被拒绝:Error Domain = NSURLErrorDomain Code = -1022
我的代码如下:
fetch('http://www.baidu.com')
.then(function(response) {
return response.json();
})
.then(function(myJson) {
console.log(myJson);
});
当我尝试将请求的连接从http更改为https时,一切正常。
完整的错误消息如下:
Possible Unhandled Promise Rejection: Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSUnderlyingError=0x6000071e9260 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSErrorFailingURLStringKey=http://www.baidu.com/, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection., NSErrorFailingURLKey=http://www.baidu.com/}}, NSErrorFailingURLStringKey=http://www.baidu.com/, NSErrorFailingURLKey=http://www.baidu.com/, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.}
>
我想知道如何设置以便Fetch的请求可以支持http连接?因为我处于开发环境中,所以没有支持https的服务器。