PolymerElements / iron-ajax

Easily make ajax requests
https://www.webcomponents.org/element/PolymerElements/iron-ajax
127 stars 113 forks source link

Polymer Iron Ajax gives 405 status error #312

Closed harishthirunahari closed 6 years ago

harishthirunahari commented 6 years ago

I am using Iron ajax(polymer 2.0) in my application to invoke an API which should include credentials while making a call.

<iron-ajax id="ajax" url="sample url" method="GET" content-type="application/json" handle-as="json" on-response="handleSuccess" on-error="handleError"> </iron-ajax>

I am calling this ajax in a button click like below

        this.$.ajax.withCredentials = true;
        this.$.ajax.headers['X-Requested-With'] = "XMLHttpRequest";
        this.$.ajax.headers['Authorization'] = this.makeHeaders(this.userid, this.password);
        this.$.ajax.generateRequest();

It is going into error which gives status as 405(method not allowed). The makeHeaders function looks like below

makeHeaders(user, password) { return "Basic " + btoa(user + ":" + password); }