我想在Dart中发送发帖请求。
curl
看起来像这样。
curl -X POST "https://api-us.faceplusplus.com/facepp/v3/search" \
-F "api_key=<api_key>" \
-F "api_secret=<api_secret>" \
-F "face_token=c2fc0ad7c8da3af5a34b9c70ff764da0" \
-F "outer_id=facesetid"
我这样尝试过,但错误响应说
MISSING_ARGUMENTS:api_key
final String apiKey = API_KEY;
final String apiSecret = API_SECRET;
final String faceToken = FACE_TOKEN;
final String outerId = OUTER_ID;
final data = jsonEncode({
'api_key': apiKey,
'api_secret': apiSecret,
'face_token': faceToken,
'outer_id': outerId
});
final http.Response request = await http.post(
'https://api-us.faceplusplus.com/facepp/v3/search',
body: data,
);
final String response = request.body;
final result = json.decode(response);
print(response);
print('------------------------');
print(result);
我想念什么?
如何正确发布?
答案 0 :(得分:2)
来自man curl
-F, --form <name=content>
(HTTP) This lets curl emulate a filled-in form in which a user has pressed the submit button. This causes curl to POST data using the Content-Type multipart/form-data
https://pub.dartlang.org/documentation/http/latest/http/MultipartRequest-class.html
var uri = Uri.parse("http://pub.dartlang.org/packages/create"); var request = new http.MultipartRequest("POST", url); request.fields['user'] = 'nweiz@google.com'; request.files.add(new http.MultipartFile.fromFile( 'package', new File('build/package.tar.gz'), contentType: new MediaType('application', 'x-tar')); request.send().then((response) { if (response.statusCode == 200) print("Uploaded!"); });