Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http post a map object using application/json content-type #17636

Closed
DartBot opened this issue Mar 19, 2014 · 3 comments
Closed

http post a map object using application/json content-type #17636

DartBot opened this issue Mar 19, 2014 · 3 comments
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. closed-not-planned Closed as we don't intend to take action on the reported issue

Comments

@DartBot
Copy link

DartBot commented Mar 19, 2014

This issue was originally filed by [email protected]


I am encountering a problem trying to use the "package:http/http.dart' pub package to post some JSON data to a web service. I have formatted the data correctly (which I confirmed by posting using the Advanced REST Client extension for Chrome) and the only difference is the Content-Type is forced to the wrong type (the web service only accepts "application/json"):

If body is a Map, it's encoded as form fields using encoding. The content-type of the request will be set to "application/x-www-form-urlencoded"; this cannot be overridden.

The documentation suggests:

For more fine-grained control over the request, use Request or StreamedRequest instead.

Why is the post content type limited to only form-urlencoded? Can the pub package be fixed to set the content type dynamically?

@sgjesse
Copy link
Contributor

sgjesse commented Mar 20, 2014

Added Area-Pkg, Pkg-Http, Triaged labels.

@nex3
Copy link
Member

nex3 commented Mar 20, 2014

The auto-encoding of Maps for [body] is just utility functionality; it makes it easier to do the common case (sending form parameters) without cutting off other possibilities. You can always post arbitrary data by passing [body] a string or a List<int>. For example:

    http.post(url,
        body: JSON.encode(data),
        headers: {'content-type': 'application/json'}));


Added NotPlanned label.

@DartBot DartBot added Type-Defect area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. closed-not-planned Closed as we don't intend to take action on the reported issue labels Mar 20, 2014
@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

This issue has been moved to dart-lang/http#16.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. closed-not-planned Closed as we don't intend to take action on the reported issue
Projects
None yet
Development

No branches or pull requests

4 participants