Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3641

Add header to http request

$
0
0

My first post here. I'm using droidscript and I have to include an header that contains a specific user and a password in order to retrieve a token. I'm having trouble because I don't know where to include those headers.

That's the code I'm using:

function btn_OnTouch(){    var url = "myurl";    SendRequest(url);}//Send an http get request.function SendRequest(url){    var httpRequest = new XMLHttpRequest();    httpRequest.onreadystatechange = function() {        HandleReply(httpRequest);    };    httpRequest.open("GET", url, true);    httpRequest.send(null);    app.ShowProgress("Loading...");}//Handle the servers reply (a json object).function HandleReply(httpRequest){    if (httpRequest.readyState == 4){        //If we got a valid response.        if (httpRequest.status == 200){            txt.SetText("Response: "+ httpRequest.status + httpRequest.responseText);        }        //An error occurred        else            txt.SetText("Error: "+ httpRequest.status + httpRequest.responseText);    }    app.HideProgress();}

The told me I should probably include the headers like this, but I don't know where to put them in my code.

httpRequest.setRequestHeader(“username”, “myuser”);httpRequest.setRequestHeader(“password”, “mypass”);

Viewing all articles
Browse latest Browse all 3641

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>