Dart 中的 Http 帖子
Posted
技术标签:
【中文标题】Dart 中的 Http 帖子【英文标题】:Http post in Dart 【发布时间】:2022-01-19 19:47:30 【问题描述】:您好,我正在研究如何在 collect2.com 上发布数据或在 dart 中发布数据 我不知道如何发送令牌到服务器
import 'package:http/http.dart' as http;
import 'dart:io';
Future<http.Response> requestMethod() async
final queryParameters =
"action": "opened",
"issue": "name": "Hello", "number": 1347,
"id": 1296269,
"full_name": "octocat/Hello-World",
"owner": "login": "octocat", "id": 1
;
final uri = Uri.https(
'collect2.com',
'/api/xxxtokenxxx/datarecord/', queryParameters);
final response = await http.post(uri, headers:
HttpHeaders.contentTypeHeader: 'application/json',
HttpHeaders.acceptHeader: 'application/json'
);
return response;
它返回如下错误:
未处理的异常: 类型 '_InternalLinkedHashMap
' 不是类型 'Iterable' 的子类型
卷曲:
curl -d '"action": "opened", "issue": "name": "Hello", "number": 1347, "repository": "id": 1296269, "full_name": "octocat/Hello-World", "owner": "login": "octocat", "id": 1' \
https://collect2.com/api/xxxtokenxxx/datarecord/ \
-H "Content-Type: application/json
【问题讨论】:
【参考方案1】: import 'package:http/http.dart' as http;
import 'dart:convert';
Future<http.Response> send()
return http.post(
Uri.parse(
'https://collect2.com/api/token/datarecord/'),
headers: <String, String>'Content- Type':'application/json;charset=UTF-8',
body: jsonEncode(<String, String>
"action": "opened",
),
);
【讨论】:
以上是关于Dart 中的 Http 帖子的主要内容,如果未能解决你的问题,请参考以下文章
Dart Flutter - 使用 Chopper 获取 WordPress 自定义帖子类型