如何处理卷筒纸颤动的心电图 [英] How to handle cors for web flutter
本文介绍了如何处理卷筒纸颤动的心电图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在努力解决我的 flutter
的 PWA
项目中的 cors
问题,我一直在关注
I have been struggle to fix the cors
problem in my PWA
project of flutter
and I am following this
我正在使用 universal_io
包,因为dart.io无法用于网络...这是代码的一部分
I am using universal_io
package since dart.io can not be used for web...here is the part of the code
HttpClient client = new HttpClient();
client.badCertificateCallback =
((X509Certificate cert, String host, int port) => true);
String url = 'https:xxxx.php';
Map map = {
"a": "a",
"b": "b"
};
HttpClientRequest request = await client.postUrl(Uri.parse(url));
request.headers.set('content-type', 'application/json');
request.add(utf8.encode(json.encode(map)));
if (request is BrowserHttpClientRequest) {
request.credentialsMode = BrowserHttpClientCredentialsMode.include;
}
HttpClientResponse response = await request.close();
print(response.toString());
String reply = await response.transform(utf8.decoder).join();
print(reply);
但是我得到这样的错误
--------------------------------------------------------------------------------
BrowserHttpClient received an error from XMLHttpRequest (which doesn't tell
reason for the error).
HTTP method: POST
URL: https://www.rscm.co.id/apirscm/v2.php
Origin: http://localhost:64121
Cross-origin request!
XmlHttpRequest 'credentials mode' is enabled.
Did the server send the following mandatory headers?
* Access-Control-Allow-Credentials: true
* Access-Control-Allow-Origin: http://localhost:64121
* In credentials mode, '*' would fail!
* Access-Control-Allow-Methods: POST
有没有办法解决这个问题?
is there a way to solve this problem?
推荐答案
您可以在chrome的调试模式下本地主机服务器,方法如下:在终端中打开它.
You can you local host server in the debug mode of chrome, here is how: open this in terminal.
open -n -a /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --args --user-data-dir="/Users/i0868/Desktop/Chrome" --disable-web-security
这篇关于如何处理卷筒纸颤动的心电图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文