64
Views
1
Comments
Mobile Development: Add Request Header when open Web View
Question

Hi

I have an issue about open web view on mobile


So this the problem. How to add request header before launch open web view (iframe or In App Browser)?

The example is add header name (x-application token) and value (kazxcffafsdfsv)


Thanks for your reply


2020-09-21 08-42-47
Vincent Koning

Hi Jonatan,

There is a javascript method to could help you. I pasted it below;

Greetings,

Vincent



source: https://stackoverflow.com/questions/17694807/how-to-set-custom-http-headers-when-changing-iframe-src

Rather than using a data URI, or setting the contents to a string, you can use URL.createObjectURL(), and set it as the src of the iframe.

var xhr = new XMLHttpRequest();

xhr.open('GET', 'some.pdf');
xhr.onreadystatechange = handler;
xhr.responseType = 'blob';
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
xhr.send();

function handler() {
  if (this.readyState === this.DONE) {
    if (this.status === 200) {
      // this.response is a Blob, because we set responseType above
      var data_url = URL.createObjectURL(this.response);
      document.querySelector('#output-frame-id').src = data_url;
    } else {
      console.error('no pdf :(');
    }
  }
}
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.