http icon indicating copy to clipboard operation
http copied to clipboard

How do I add a type to multipart request field?

Open szymonmazanik opened this issue 3 years ago • 1 comments

I have a backend endpoint that requires having ;type=application/json at the end of the field's content. Otherwise, it throws 415 error. Here is working curl: curl --location --request POST 'https://example.com' --form 'account="{\"student\":null,}";type=application/json'

From what I discovered we can only pass the form data as a Map, without any additional arguments. Is it possible to achieve the same thing as in curl example with this package?

szymonmazanik avatar Jan 06 '22 22:01 szymonmazanik

var request = http.MultipartRequest('POST', uri);
request.fields['id'] = 'some_id';
request.fields['account'] = json.encode({student:null}) + ';type=application/json';

// Make sure that's the last field to ensure it shows at end of the URL

I hope it solves the issue you are facing.

AmanNegi avatar Sep 01 '22 18:09 AmanNegi