【问题标题】:how to execute a https post request using curl in flutter如何在flutter中使用curl执行https post请求
【发布时间】:2019-09-25 11:17:04
【问题描述】:

我是使用 curl 的新手,我正在尝试使用 curl 执行 https 发布请求。它似乎不像其他 json 发布请求那样工作,所以我希望有人可以向我解释这一点

【问题讨论】:

  • 在应用程序中使用 curl 没有意义,不是为此而生的,只需将其转换为常规的 http 请求

标签: http curl flutter


【解决方案1】:

我不确定我是否充分理解了你的答案,但你可以看看这个Packagethis one,后者提供了更多的灵活性和拦截器等功能。

【讨论】:

    【解决方案2】:

    你可以使用这个包Curl https://pub.dev/packages/curl

    示例代码

    import 'package:curl/curl.dart';
    import 'package:http/http.dart';
    
    final req1 = new Request("GET", "https://exyui.com/endpoint");
    print(toCurl(req1));
    // will print out:
    // curl 'https://exyui.com/endpoint' --compressed --insecure
    
    final req2 = new Request("PUT", "https://exyui.com/endpoint");
    req2.body = "This is the text of body?, \\, \\\\, \\\\\\";
    print(req2);
    // will print out:
    // curl 'https://exyui.com/endpoint' -X PUT -H 'content-type: text/plain; charset=utf-8' --data-binary \$'This is the text of body\\ud83d\\ude05, \\, \\\\, \\\\\\' --compressed --insecure
    
    final req3 = new Request("POST", "https://exyui.com/endpoint");
    final part1 = "This is the part one of content";
    final part2 = "This is the part two of content?";
    final expectQuery = "part1=This%20is%20the%20part%20one%20of%20content&part2=This%20is%20the%20part%20two%20of%20content%F0%9F%98%85";
    req3.bodyFields = {
    "part1": part1,
    "part2": part2,
    };
    print(toCurl(req3));
    

    【讨论】:

      猜你喜欢
      • 2020-02-09
      • 1970-01-01
      • 2012-11-26
      • 1970-01-01
      • 2014-08-25
      • 1970-01-01
      • 2012-11-15
      • 2013-01-05
      • 2014-10-10
      相关资源
      最近更新 更多