How to do POST in Dart command line HttpClient -


i'm struggling putting dart command line client capable of doing http post. know can not use dart:html library , have use dart:io

the beginning seems simple:

httpclient client = new httpclient(); client.geturl(uri.parse("http://my.host.com:8080/article")); 

the question is: correct syntax , sequence make httpclient post , able pass json-encoded string post?

use http package , dart:convert

import 'package:http/http.dart' http; import 'dart:convert';  void main() {     var url = 'http://httpbin.org/post';   http.post(url, body: json.encode({'test': 'value'})).then((response) {     print("response status: ${response.statuscode}");     print("response body: ${response.body}");   }); } 

for adding custom headers, handling errors etc. see https://www.dartlang.org/dart-by-example/#making-a-post-request


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -