http
http copied to clipboard
How do I add a type to multipart request field?
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?
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.