Dart 中的 Http post
Http post in Dart
你好,我正在弄清楚 post 数据如何在 collect2.com 或 post 数据上飞镖
我不知道如何将令牌发送到服务器
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;
}
它 return 错误如下:
Unhandled exception:
type '_InternalLinkedHashMap<String, Object>' is not a subtype of type '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
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",
}),
);
}
你好,我正在弄清楚 post 数据如何在 collect2.com 或 post 数据上飞镖 我不知道如何将令牌发送到服务器
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;
}
它 return 错误如下:
Unhandled exception: type '_InternalLinkedHashMap<String, Object>' is not a subtype of type '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
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",
}),
);
}