如何指定 Flutter/dart HTTP 协议版本 (HTTP/1.1, --http1.1)

问题描述

我正在使用 dart:http 发出发布请求,但似乎我无法指定目标 api 所需的 HTTP1.1 版本。理想情况下,我需要在 dart 中重新创建以下请求:

curl -X POST --http1.1 "https://api.dummyapi.com/v1/route" -H "accept: text/plain" -H "Authorization: 000000-000000-000000-000000" -H "Content-Type: application/json-patch+json" -d "{}"

我目前的版本是这样的:

    final url = Uri.parse('https://api.dummyapi.com/v1/route');

    final response = await http.post(url,headers: {
      'Authorization': '000000-000000-000000-000000','accept': 'text/plain','Content-Type': 'application/json'
    });```

解决方法

Checked the following code example



  Future createUserExample(Map<String,dynamic> data) async {
final http.Response response = await http.post(
    'https://api.dummyapi.com/v1/route',headers: <String,String>{
      'Authorization': '000000-000000-000000-000000','accept': 'text/plain','Content-Type': 'application/json'
    },body: data,);
return response;