ionic-team / capacitor-docs

https://capacitorjs.com/docs
Apache License 2.0
20 stars 196 forks source link

Missing Crucial Information To Send JSON Data With CapacitorHttp #232

Closed Ryan-Rante closed 3 months ago

Ryan-Rante commented 8 months ago

URL Capacitor Official Plugins HTTP

What is missing or inaccurate about the content on this page? I only found the issue at Android platform. The API server does not receive JSON data if you try to request it without explicity send header Content-Type application/json.

I have read the Java base code and it actually skips the process of writing data if you try to request data without Content-Type header.

If you want to send data JSON with Android platform, you need to add header Content-Type with application/json like this.

const ret = await CapacitorHttp.post({
    ...
    data: {
        message: 'Hello World!'
    },
    headers: {
        "Content-Type": "application/json"
    },
    ...
});

For other type of data, if I had time, I would try one by one.

jcesarmobile commented 3 months ago

This is a bug in the plugin, not in the docs https://github.com/ionic-team/capacitor/issues/7245