'send --data instead of --data-binary with dio
How can I send --date instead of --data-binary with dio?
This what was sent by my app:
curl -H "user-agent: Dart/2.16 (dart:io)"
-H "content-type: application/json; charset=utf-8"
-H "cookie: .AspNetCore.Antiforgery.2P6hghJyI_0=CfDJ8JIsTfPvFe9Jp0k0BFtfKI6c7PZHrgS4GYI3Oj6mYmKhIC_-gt17WIqFYNXnbsUwh3jhmHANEFELDUG6qv3qwv_owqHnqFFypKKaziFB3Lib3e4uytVLE-DlAmwBFOnY8Iqih3s9HY_lPCRPM_-JP1k"
-H "host: auth.my-serv.dev"
--data-binary "{\"returnUrl\":\"/connect/authorize/callback?response_type=code&client_id=courier_mobile_app&redirect_uri=courier-mobile-app%3A%2F%2Fauth%2Flogin&scope=openid%20offline_access&code_challenge=ls8FRqIka50symbO6IzNEYypi4TuajRYRWIxw4NbOg8&code_challenge_method=S256\",\"username\":\"79001231201\",\"password\":\"Qq135790\",\"tenantName\":\"tenant_name\",\"countryCode\":\"Ru\",\"authMethod\":\"local\",\"__RequestVerificationToken\":\"CfDJ8JIsTfPvFe9Jp0k0BFtfKI7hbqzUXyIeD-cHekq8S76MpQwFzMzy_CTQPPYX-Jf0wNII4f_0UvIq0xHttqYMSEUeb4oZi12FxXBxuQuBz6oZH7mFRjKczmD3I2Nod6CzMesDBZTYfimHcqE5ihC4zQk\",\"RememberLogin\":false}" --compressed "https://auth.my-serv.dev/account/login"
And this is a working request from Postman that I need:
curl -H "cookie: .AspNetCore.Antiforgery.2P6hghJyI_0=CfDJ8JIsTfPvFe9Jp0k0BFtfKI4ud1W9XtsM5q8us3ayVDkJFHiYXu2Ia4iTcl-bEIOxSj-B9zua8j60IKgCZzKTrzQGIYdGR6wmkH3u4IIMccm-6GGT7fcZ9fztXsDXQRPvDmWs-sb64vvK6pyxE6vAoYU"
-H "User-Agent: PostmanRuntime/7.29.0"
-H "Accept: */*"
-H "Postman-Token: da2c0d09-45c6-40e8-9f9d-8c29f3ca287a"
-H "Host: auth.my-serv.dev"
--data "ReturnUrl=%2Fconnect%2Fauthorize%2Fcallback%3Fresponse_type%3Dcode%26client_id%3Dcourier_mobile_app%26redirect_uri%3Dcourier-mobile-app%253A%252F%252Fauth%252Flogin%26scope%3Dopenid%2520offline_access%26code_challenge%3Dls8FRqIka50symbO6IzNEYypi4TuajRYRWIxw4NbOg8%26code_challenge_method%3DS256&Username=name&Password=password&TenantName=tenant_name&CountryCode=Ru&authMethod=local&__RequestVerificationToken=CfDJ8JIsTfPvFe9Jp0k0BFtfKI5r7F4KJMcvGHuM7WxDqafePwXnltXwQs_iy5LFhY8X8eqwuzYkxT_UwqnqTm2G86k_8ZbcKT37I-_MXXjpr0Drr0BX2ms6ML7SrcYe4mP_A9b_xvTQglB3rNW18Lp2kH4&RememberLogin=false"
--compressed "https://auth.my-serv.dev/account/login"
My code is:
Map<String, dynamic> loginBody = {
'returnUrl':
'/connect/authorize/callback?response_type=code&client_id=courier_mobile_app&redirect_uri=courier-mobile-app%3A%2F%2Fauth%2Flogin&scope=openid%20offline_access&code_challenge=ls8FRqIka50symbO6IzNEYypi4TuajRYRWIxw4NbOg8&code_challenge_method=S256',
'username': 'name',
'password': 'password',
'tenantName': 'tenent_name',
'countryCode': 'Ru',
'authMethod': 'local',
'__RequestVerificationToken': requestVerificationToken,
'RememberLogin': false,
};
var urlString2 = protocol + baseUrl + '/account/login';
try {
response = await dio.post(urlString2, data: loginBody);
} on DioError catch (e) {
print('Request failed with status: ${e.response?.data}');
}
UPDATE Following @richard-heap advice made
Map<String, String> loginBody = {
and
'RememberLogin': 'false',
Still my date is sent with --data-binary
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
