Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 来自FlatterWeb的HTTP Post请求_Flutter_Google Cloud Functions_Xmlhttprequest_Flutter Web_Flutter Http - Fatal编程技术网

Flutter 来自FlatterWeb的HTTP Post请求

Flutter 来自FlatterWeb的HTTP Post请求,flutter,google-cloud-functions,xmlhttprequest,flutter-web,flutter-http,Flutter,Google Cloud Functions,Xmlhttprequest,Flutter Web,Flutter Http,我在谷歌云上有一个函数,我正试图在我的Flitter web应用程序中向它发出post请求。我用Python测试了一个post请求,它可以处理以下请求: params = {'input_key':'input_value'} headers = {"Content-Type": "application/json"} r = requests.post("https://us-central1-lucid-bond-261904.cloudfu

我在谷歌云上有一个函数,我正试图在我的Flitter web应用程序中向它发出post请求。我用Python测试了一个post请求,它可以处理以下请求:

params = {'input_key':'input_value'}
headers = {"Content-Type": "application/json"}
r = requests.post("https://us-central1-lucid-bond-261904.cloudfunctions.net/cloudFunction", data=jason.dumps(params), headers=headers)
但是,当我尝试使用http包从我的Flatter web应用程序执行相同的请求时,我不断收到XMLHttpRequest错误。这是我在Flitter web应用程序中的http请求

String path = "https://us-central1-lucid-bond-261904.cloudfunctions.net/cloudFunction";
Map params = {'input_key':'input_value'}
var response = await http.post(path, body: json.encode(params), headers: <String, String>{'Content-Type': 'application/json'});
还有我的云函数中的错误

line 99, in cloudFunction shop_name = inputs_dict['input_key'] TypeError: 'NoneType' object is not subscriptable

EDIT:刚刚尝试了邮递员发出的同样的发帖请求,结果成功。但仍然无法从我的颤振应用程序中运行。我需要在谷歌云功能中启用CORS或其他功能吗?

我终于成功了。在我的云函数中,request.get_json()返回null。当我添加参数force=True时,它终于起作用了。当通过python或postman触发函数时,我不必执行force=True,但出于某种原因,通过flift触发函数需要force=True

request.get_json(force=True)

伟大的,伟大的,伟大的研究!我有一个完全相同的情况(post请求是curl命令可调用的,但从flutte web无法发送),并用您的解决方案解决了它。对于那些提出这种情况的人来说,这不是CORS的问题!
request.get_json(force=True)