嗨,我正在弄清楚如何在 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;
}
它回傳這樣的錯誤:
Unhandled exception:
type '_InternalLinkedHashMap<String, Object>' is not a subtype of type 'Iterable<dynamic>'
卷曲:
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
uj5u.com熱心網友回復:
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",
}),
);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/385590.html
