Authorization header not working in nativescript


I am making a request to a RestAPI made on DjangoRestFramework using NativeScript for Angular with the next code:

getImages() {
    let headers = new Headers();
    headers.append("Content-Type", "application/json");
    headers.append('Authorization', 'Basic YWRtaW5jaHVwaXRvczpDaHVwaXRvczIwMTguKg==');

    return this.http.get(
      Config.apiUrl + "images",
      { headers: headers}
    .map(response => response.json())

However, the API sends the next message:

{“detail”:“Authentication credentials were not provided.”}

I have tested the request using PostMan an it works so I don’t know what I’m missing. Thanks in advance for any help!


hi, can you try something like the below, using http.request and passing in the headers like thus. The other issue may have to do with encoding your key properly: I have to do that when using MailGun. Try one or both of these?

         url: "",
         method: "POST",
            headers: {
                 "Content-Type": "application/json",
                  "Authorization": "Key e65d726322664ad1b046fb5ee074114c",


I was having an issue (Java errors on Android) when using http.getImage with basic auth. The code I was using all declared new Headers() and did headers.set(). Switching to the suggested method of inline, manually constructed headers object in the options object worked for me.

This was a solution for me, thank you.