Cordova Android App can't post 403 Forbidden

1.6k Views Asked by At

I have a Java REST Service which takes post request. My Cordova packaged as Android App cannot make a post request.

I get a 403 Forbidden error. I know many people have given many suggestions. I've tried all of those but still can't solve. Any help will help greatly.

My Cordova config file looks like this.

<content src="index.html" />
<plugin name="cordova-plugin-whitelist" spec="1" />    
    <access origin="*" />
<access uri="*" subdomains="true" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
    <allow-intent href="*" />
</platform>
<platform name="ios">
    <allow-intent href="itms:*" />
    <allow-intent href="itms-apps:*" />
</platform>

I tried removing based on suggestion from someone. But still doesn't work.

2

There are 2 best solutions below

0
On

Do you use cookies in Ajax?

var request = new XMLHttpRequest(),
    data = {name:'name'},
    url = 'https://example.com';
request.setRequestHeader("cookieItem1", "cookieContent1");
request.setRequestHeader("cookieItem2", "cookieContent2");
request.open("POST", url);
request.send(JSON.stringify(data));

I tried this to resolve this.

0
On

Just in case someone comes across this. The problem maybe due to a CORS issue. Usually http calls from within a cordova app have the origin=file:// header set. Some web server may have a security filter to prevent security attacks.

The easiest will be to make sure the server that you are doing the http request do not block them if the origin header has the file:// value. See here

Otherwise you will need to find a way to change the header to something else before making the request.