# Http authentication

**URL:** <https://discourse.processing.org/t/http-authentication/828>\
**Category:** Coding Questions\
**Created:** [June 10, 2018, 5:07am UTC](https://discourse.processing.org/t/http-authentication/828 "2018-06-10T05:07:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stanleyseow](https://avatars.discourse-cdn.com/v4/letter/s/aeb1de/32.png) [@stanleyseow](https://discourse.processing.org/u/stanleyseow)\
**Post date:** [June 10, 2018, 5:07am UTC](https://discourse.processing.org/t/http-authentication/828/1 "2018-06-10T05:07:09Z")

</div>

I tried to use the httpDo() with the following code for basic authentication but it is not working, can someone advise on this ?

I got a “Failed to load resource: the server responded with a status of 401 (Unauthorized)” from the server in the console."

```auto
apiMetrics = "http://somehost.com/api/v2/monitoring/metrics";

function setup() {
    createCanvas(400, 400)
    var url = apiMetrics;

    httpDo(
        url, {
            method: 'GET',
            headers: {
                authorization: 'Basic username:password'
            }
        },
        function (data) {
            console.log(data);
        }
    )
}

```

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [June 10, 2018, 5:31am UTC](https://discourse.processing.org/t/http-authentication/828/2 "2018-06-10T05:31:58Z")

</div>

Is that a valid link? I couldn’t get it to work. If you post this link in your browser, do you get the same error? That would be my first test.

Kf

---

<div class="post-metadata">

**Author:** ![stanleyseow](https://avatars.discourse-cdn.com/v4/letter/s/aeb1de/32.png) [@stanleyseow](https://discourse.processing.org/u/stanleyseow)\
**Post date:** [June 10, 2018, 5:51am UTC](https://discourse.processing.org/t/http-authentication/828/3 "2018-06-10T05:51:03Z")

</div>

Yes, i removed the actual link…

If I goto the URL manually, I was prompted with username & password and after I login, I get this json data …

```auto
{
"code":0,
"result":[
{
"emq@127.0.0.1":{
"packets/pubrec/sent":7,
"packets/pubrec/missed":0,
"messages/sent":373843,
"packets/unsubscribe":0,
"packets/pubcomp/received":9,
"packets/suback":340,
"messages/qos2/sent":9,
"messages/received":430641,
"bytes/sent":18948545,
"packets/pingresp":16333,
"packets/connect":453,
"packets/sent":390992,
"messages/qos1/sent":0,
"packets/pubrel/missed":0,
"packets/puback/missed":0,
"bytes/received":22125284,
"messages/dropped":58515,
"packets/pubrel/received":7,
"packets/pubrec/received":9,
"messages/retained":3,
"messages/qos0/sent":373834,
"packets/pubrel/sent":9,
"packets/pubcomp/missed":0,
"packets/pubcomp/sent":7,
"packets/connack":453,
"packets/received":448000,
"packets/publish/sent":373843,
"packets/pingreq":16333,
"packets/publish/received":430641,
"packets/disconnect":208,
"messages/qos2/received":7,
"messages/qos1/received":0,
"packets/subscribe":340,
"packets/puback/sent":0,
"packets/puback/received":0,
"messages/qos2/dropped":0,
"messages/qos0/received":430634,
"packets/unsuback":0
}
}
]
}

```

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [June 10, 2018, 2:45pm UTC](https://discourse.processing.org/t/http-authentication/828/4 "2018-06-10T14:45:03Z")

</div>

Is this solved or are you still inquiring how to do it? Just dbl checking…

Kf

---

<div class="post-metadata">

**Author:** ![stanleyseow](https://avatars.discourse-cdn.com/v4/letter/s/aeb1de/32.png) [@stanleyseow](https://discourse.processing.org/u/stanleyseow)\
**Post date:** [June 12, 2018, 9:25am UTC](https://discourse.processing.org/t/http-authentication/828/5 "2018-06-12T09:25:12Z")

</div>

> [@stanleyseow](#):
>
> Failed to load resource: the server responded with a status of 401 (Unauthorized)

No, it is not resolved yet, I still cannot do authorization: 'Basic ’ method yet using httpDo …
