angularjs - JavaScript - comparing two same strings but they are not equal -
i use angularjs $http
send request, basic authorization provided headers 'authorization': this.basicauthorization
but doesn't work, found out there problem in this.basicauthorization
. when replace string 'basic some_base64_encoded_string'
this.basicauthorization = 'basic'+' '+ btoa('username'+';'+'password'); this.mystring = 'basic some_base64_encoded_string'; console.log(this.basicauthorization + " " + typeof this.basicauthorization + " lenght " + this.basicauthorization.length); console.log(this.mystring + " " + typeof this.mystring + " length " + this.mystring.length); if(this.basicauthorization == this.mystring){ console.log("equal") } else{ console.log('not equal'); console.log(this.basicauthorization + " " + typeof this.basicauthorization + " lenght " + this.basicauthorization.length); console.log(this.mystring + " " + typeof this.mystring + " length " + this.mystring.length); }
and see in console is
not equal
basic some_base64_encoded_string string 82
basic some_base64_encoded_string string 82
why strings not equal , why when use btoa() http request not working , when provide this.mystring
works
change:
this.basicauthorization = 'basic'+' '+ btoa('username'+';'+'password');
to:
this.basicauthorization = 'basic'+' '+ btoa('username'+':'+'password');
in basic authentication username , password must seperated :
. see http authentication rfc.
Comments
Post a Comment