Hi,
I use CapacitorHttp.post for request, in web work fine but don’t in emulator android studio
the error is:
E/Capacitor/Plugin: JSONException
org.json.JSONException: JSValue could not be coerced to JSObject.
at com.getcapacitor.JSValue.toJSObject(JSValue.java:39)
at com.getcapacitor.plugin.util.CapacitorHttpUrlConnection.setRequestBody(CapacitorHttpUrlConnection.java:194)
at com.getcapacitor.plugin.util.HttpRequestHandler.request(HttpRequestHandler.java:399)
at com.getcapacitor.plugin.CapacitorHttp$1.run(CapacitorHttp.java:34)
at java.lang.Thread.run(Thread.java:764)
this is my code
...
const options = {
url: scriptName,
headers: {
'X-Requested-With': 'XMLHttpRequest',
"Content-Type": (!isFile ? "application/x-www-form-urlencoded": "multipart/form-data"),
"Accept": "application/json"
},
data: (!isFile ? args.join("&"): args),
};
const response: HttpResponse = await CapacitorHttp.post(options);
if (response.status !== 200) {
console.log("Respuesta invalida");
if (!inBackground){ await hideLoading(); }
await errorMsg("El servidor no response");
throw "Error de conexion"
}
if (response.data.errorState){
if (!inBackground){ await hideLoading(); }
await errorMsg(response.data.msgState);
throw response.data.msgState;
}
return response.data.args