Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
139
rated 0 times [  140] [ 1]  / answers: 1 / hits: 34617  / 9 Years ago, mon, may 11, 2015, 12:00:00

this question is partly pointing to my previous question :
Ionic + Angular POST request return state 404



But i wasn't able to find working solution.



Problem is following:



if I do request from the mobile app running on the device i always get response 404:



Request Method:POST
Status Code:404 Not Found (from cache)
Request Headersview source
Accept:application/json, text/plain, */*
Content-Type:text/plain
Origin:file://
User-Agent:Mozilla/5.0 (Linux; Android 4.4.2; Lenovo Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36
Request Payloadview source
{,…}


But if i tried the same request on the desktop using Postman plugin in the Chrome browser i always get response 200 with data what i need.



I thought that it was issue caused by Angular http method but in previous post i was noticed that is not true.



How can i avoid this please? Should i set some headers in HTML of the app, during the request or on the server side (PHP)?



Many thanks for any advice.



EDIT:



I tried also set cache:false by this way:



$http({
method : 'POST',
url : $scope.remoteUrl,
data: postData,
headers: headersData,
cache: false,
timeout: 10000
// success response
})


But without luck.


More From » php

 Answers
18

A lot of people are experiencing that.


I just ran into the same problem. It seems it has to do with a new security policy in new versions of Cordova.


Here's how I solved it:


I installed Cordova's whitelist plugin :


cordova plugin add cordova-plugin-whitelist

Then, add your content policy in your index.html as a meta tag (using your own host or '*' for accepting all requests) :


<meta http-equiv="Content-Security-Policy" content="default-src 'self' yourhost.com ws://localhost:35729 data: gap: https://ssl.gstatic.com; style-src 'self' 'unsafe-inline'; media-src *;script-src 'self' localhost:35729 'unsafe-eval' 'unsafe-inline';">

default-src is used for general requests; the ws://localhost:35729 host is used for live-reload in ionic serve.


script-src is used for secure script execution


unsafe-inline and unsafe-eval are required in order for angular to work properly.


data: gap: https://ssl.gstatic.com is only used on iOS.


self means the current host of the index.html file.



You'll have to add your own in order for your requests to work. Don't forget to add the protocol and the port if they're non-standard


You can skip the meta tag if you don't want it, but you'll get a lot of warnings from the whitelist plugin.



More info on how to configure this in the plugin's readme.


Then rebuild your app, and it should work again.


[#66649] Friday, May 8, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dominickmackenziet

Total Points: 583
Total Questions: 101
Total Answers: 117

Location: Saint Lucia
Member since Wed, Feb 8, 2023
1 Year ago
dominickmackenziet questions
Wed, Apr 7, 21, 00:00, 3 Years ago
Fri, Feb 12, 21, 00:00, 3 Years ago
;