0

i call https from app.js on ionic framework, but unable to get the data, on console there show "reason: missing token 'authorization' in CORS header 'Access-control-allow-headers from cors preflight channel'"

i test on firefox restclient everything working ok.

also i am test curl on mac terminal also can get the data back.

curl --user wes:1231231 http://192.168.1.1/wordpress/wp-json/users/

but the following code on ionic framework it's showing error on console

cross-origin request blocked: this same origin policy disallows reading the remote resource at http://192.168.1.113/wordpress/users.(reason: missing token 'authorization' in CORS header 'Access-control-allow-headers from cors preflight channel'

var string = $base64.encode('wes' + ':' + '1231231');
$http({
   method: 'GET', 
   url 'http://192.168.1.1/wordpress/wp-json/users/',
   headers:{'Authorization': 'Basic '+ string }
})
.success(function(data, status){
   console.log(data);
});
4

1 Answer 1

4

ok problem solve, ionic framework + wp json api

because problem console show we missing token 'authorization' in CORS header 'Access-control-allow-headers from cors preflight channel

going to json-rest-api plugin files open plugin.php

search Access-Control-Allow-Origin

add header( 'Access-Control-Allow-Headers: Authorization, Content-Type' );

problem solve, because we need a authorization header.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.