Hi im trying to send post request with basic auth in Cordova Ionic Framework v6, but the console log response if im not adding it. Here is screenshot from console log when i added basic auth:
Console log when use basic auth:
Im following tutorial from ionic documentation ionic documentaion http and the github one cordova-plugin-advanced-http.
but when i didnt use basic auth the header added, i tried with some code like:
this.http.useBasicAuth('user', 'password');
adding directly to header param :
this.http.post('someURL', {"username" :username, "password" :password}, {'Authorization': 'Basic ZHJlYW1fMS4wOmRyZWFtXzEuMA==', 'Accept': 'application/json', 'Content-Type':'application/x-www-form-urlencoded'})
but the response always like the image 1 the header not added. Any solution for this porblem ?, or maybe I am missing something ?.
Heres my code :
import { HTTP } from '@awesome-cordova-plugins/http/ngx';
constructor(private http: HTTP) {}
call(){
this.http.post('url', {"username" :variable username, "password" : variable password}, { 'Authorization': 'Basic ZHJlYW1fMS4wOmRyZWFtXzEuMA==', 'Accept': 'application/json', 'Content-Type':'application/x-www-form-urlencoded'})
.then(res=> {
console.log(res);
})
.catch(err=> {
console.log(err);
});
}
thank you in advance.
Running browser in insecure mode allows the ionic native http to work in the browser.
run
google-chrome --disable-web-security --user-data-dir="~/insecure_data_blabla"
(Linux)And open your development server in it.