javascript - Ionic + Angular POST request return state 404 -


i updated on new version on angular + ionic , method processing remote request stopped working , returns 404 response.

request following:

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, gecko) version/4.0 chrome/30.0.0.0 mobile safari/537.36 request payloadview source {,…} 

code of method processing remote request following:

    // set transfer credentials                 $http({                     method : 'post',                     url : $scope.remoteurl,                     data: {img_base64: "/9j/4aaqskz"},                     headers: 'application/json',                     timeout: 10000                     // success response                 }).success(function(data, status, headers, config) {                     //sucesss                     } else {                     //processing error                      }                      // error response                 }).error(function(data, status, headers, config) {                     // error                 }); 

i tried solve using topic:

angularjs $http.post() not send data

and

angular + ionic post request getting 404 not found

but without luck.

server side processing request way:

$inputjson = file_get_contents('php://input');     $input= json_decode( $inputjson, true ); //convert json array 

if i'm trying send request using postman or curl seems working.

ionic info:

node version: v0.12.2 cordova cli: 5.0.0 ionic cli version: 1.3.22 xcode version: xcode 6.3.1 build version 6d1002  ios-sim version: not installed ios-deploy version: not installed 

angularjs version:

"version": "1.3.13", 

how can solve please?

many advice

hum, ran same problem: header suggests has been fetched from cache... actually, seems has new security policy in new versions of cordova.

here's how solved it:

i installed cordova's whitelist plugin :

cordova plugin add cordova-plugin-whitelist 

then, add content policy in index.html meta tag (using own host or '*' accepting 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 used general requests; ws://localhost:35729 host used live-reload in ionic serve.

script-src used secure script execution

unsafe-inline , unsafe-eval required in order angular work properly.

data: gap: https://ssl.gstatic.com used on ios.

self means current host of index.html file.

you'll have add own in order requests work. don't forget add protocol , port if they're non-standard

you can skip meta tag if don't want it, you'll lot of warnings whitelist plugin.

more info on how configure in the plugin's readme.

then rebuild app, , should work again.


Comments