Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flutter post request with header and body

Tags:

flutter

anyone could help me to write flutter request post for the following header and body with the corresponding response below;

Example Post Request

Header Request:

Content-Type:application/x-www-form-urlencoded

Body Request:

grant_type: client_credentials

scope: accounts

client_assertion_type: code**

client_assertion: code**
like image 654
Hussain Avatar asked Nov 07 '22 14:11

Hussain


1 Answers

Try the following,

String hostname = "myhostname";// example
String port = "1234"; //example
String url = "https://$hostname:$port/as/token.oauth2";
String body = "{'grant_type' : '$client_credentials' }" +
              "'scope' : '$accounts'" +
              //... etc etc 
              "'Corresponding Response': { 'access_token': 'JWt CODE', 'expires_in': '86400', 'token_type': 'bearer', 'scope': 'payments' }"+
             "}";
var res = await http.post(Uri.encodeFull(url),
        headers: {
          "Accept": "application/json",
          "Content-Type" : "application/x-www-form-urlencoded"
        },
        body: body);
like image 92
F-1 Avatar answered Nov 15 '22 06:11

F-1