Xiao Xinqi
Xiao Xinqi

Reputation: 521

ionic framework wp rest api basic authorization not working

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);
});

Upvotes: 0

Views: 3596

Answers (1)

Xiao Xinqi
Xiao Xinqi

Reputation: 521

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.

Upvotes: 4

Related Questions