Skip to content

formUrlEncodedContentType not working properly with Map<String, Object> #2415

Open
@ndevev

Description

@ndevev

Package

dio

Version

5.8.0+1

Operating-System

iOS

Adapter

Default Dio

Output of flutter doctor -v

Dart Version

3.7.0

Steps to Reproduce

Original code which doesn't work:
Map data = {
'hardwareMajor': 4,
'hardwareMinor': 0,
'type': 'stable',
};

Response response = await dio.post('/native/get_last_fw_version', data: data,
  options: Options(
    contentType: Headers.formUrlEncodedContentType,
    responseType: ResponseType.plain,
  ),
);

With some modification it works properly:
Map<String, String> data = {
'hardwareMajor': '4',
'hardwareMinor': '0',
'type': 'stable',
};

Response response = await dio.post('/native/get_last_fw_version', data: data,
  options: Options(
    contentType: Headers.formUrlEncodedContentType,
    responseType: ResponseType.plain,
  ),
);

But as per the docs the original should work too:
// Instance level
dio.options.contentType = Headers.formUrlEncodedContentType;
// or only works once
dio.post(
'/info',
data: {'id': 5},
options: Options(contentType: Headers.formUrlEncodedContentType),
);

Expected Result

on the server:
hardwareMajor=4&hardwareMinor=0&type=stable

Actual Result

on the server:
{hardwareMajor: 4, hardwareMinor: 0, type: stable}

Metadata

Metadata

Assignees

No one assigned

    Labels

    h: need triageThis issue needs to be categorizeds: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions