【问题标题】:How to specify Flutter/dart HTTP protocol version (HTTP/1.1, --http1.1)如何指定 Flutter/dart HTTP 协议版本(HTTP/1.1,--http1.1)
【发布时间】:2021-03-25 13:59:27
【问题描述】:

我正在使用 dart:http 发出 post 请求,但似乎我无法指定目标 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'
    });```

【问题讨论】:

    标签: flutter dart dart-http


    【解决方案1】:
    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;
    

    【讨论】:

    • 非常感谢,看来 body: "{}" 成功了!
    猜你喜欢
    • 2016-04-15
    • 2017-09-25
    • 2017-07-16
    • 2015-10-22
    • 1970-01-01
    • 2015-03-21
    • 2015-02-13
    • 2016-04-22
    • 2011-04-13
    相关资源
    最近更新 更多