Last active
September 30, 2019 10:23
-
-
Save Abdullamhd/49f62b0d4232696627526e8b7c2b740d to your computer and use it in GitHub Desktop.
post json into server from dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:http/http.dart' as http; | |
| import 'dart:convert'; | |
| void main() async { | |
| var url = 'http://localhost:3000/'; | |
| var body = jsonEncode({ | |
| 'name' : 'Abood', | |
| 'Color' : 'blue' | |
| }); | |
| var headers = { | |
| 'content-type': 'application/json' | |
| }; | |
| var response = await http.post(url,headers : headers ,body:body ); | |
| print(response.statusCode); | |
| print(response.body); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment