# Http get socket hang up!

**URL:** <https://discourse.nodered.org/t/http-get-socket-hang-up/11603>\
**Category:** General\
**Created:** [27 May 2019 13:48 UTC](https://discourse.nodered.org/t/http-get-socket-hang-up/11603 "2019-05-27T13:48:37Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![BartosIstvan](https://avatars.discourse-cdn.com/v4/letter/b/ecd19e/32.png) [@BartosIstvan](https://discourse.nodered.org/u/BartosIstvan)\
**Post date:** [27 May 2019 13:48 UTC](https://discourse.nodered.org/t/http-get-socket-hang-up/11603/1 "2019-05-27T13:48:37Z")

</div>

Hello  
I'm trying to send a http get request to my API to get json data. To access my API I need to pass a token in the http.header. The Node-red runs on a Simatic IOT2040 and my API is running local on my PC. With postman I can get the json response .

 ![forumra](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/709e4ccb7ac8b87e62000419bab46b83d5272c35.png)  
I have created a node but gets the folowing error:  
 ![forumra2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/5/54c5ff2f2ed6f5f4dfcb6daaf4a7bac11f188166.png)  
This is my node:  
[{"id":"fd84bd47.81a15","type":"http request","z":"af66aab4.ccac18","name":"GET from API","method":"GET","ret":"txt","url":"[http://192.168.200.112:60736/api/Device","tls":"","x":715,"y":515,"wires":[["4d2ca3ad.a559cc](http://192.168.200.112:60736/api/Device%22,%22tls%22:%22%22,%22x%22:715,%22y%22:515,%22wires%22:%5B%5B%224d2ca3ad.a559cc)"]]}]

---

<div class="post-metadata">

**Author:** ![BartosIstvan](https://avatars.discourse-cdn.com/v4/letter/b/ecd19e/32.png) [@BartosIstvan](https://discourse.nodered.org/u/BartosIstvan)\
**Post date:** [27 May 2019 13:51 UTC](https://discourse.nodered.org/t/http-get-socket-hang-up/11603/2 "2019-05-27T13:51:27Z")

</div>

In the debug tab I get the following errors  
 ![forumra3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/2078f260790c7d92fb53e1d819f20ce11738c18b.png)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [27 May 2019 14:05 UTC](https://discourse.nodered.org/t/http-get-socket-hang-up/11603/3 "2019-05-27T14:05:50Z")

</div>

you will need a change node or function node before that set set your msg.headers as you need.

---

<div class="post-metadata">

**Author:** ![BartosIstvan](https://avatars.discourse-cdn.com/v4/letter/b/ecd19e/32.png) [@BartosIstvan](https://discourse.nodered.org/u/BartosIstvan)\
**Post date:** [27 May 2019 14:21 UTC](https://discourse.nodered.org/t/http-get-socket-hang-up/11603/4 "2019-05-27T14:21:39Z")

</div>

> [@dceejay](#):
>
> change node

Thank you for answearing. I added a change node . But I think I did not catch exactly your idea .  
[{"id":"fd84bd47.81a15","type":"http request","z":"af66aab4.ccac18","name":"GET from API","method":"GET","ret":"txt","url":"[http://192.168.200.112:60736/api/Device","tls":"","x":715,"y":515,"wires":[["4d2ca3ad.a559cc](http://192.168.200.112:60736/api/Device%22,%22tls%22:%22%22,%22x%22:715,%22y%22:515,%22wires%22:%5B%5B%224d2ca3ad.a559cc)"]]}]

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [27 May 2019 14:37 UTC](https://discourse.nodered.org/t/http-get-socket-hang-up/11603/5 "2019-05-27T14:37:37Z")

</div>

There is no change node in the flow you shared. Can you repost the flow so we can have a look on how you are setting `msg.headers` ?

---

<div class="post-metadata">

**Author:** ![BartosIstvan](https://avatars.discourse-cdn.com/v4/letter/b/ecd19e/32.png) [@BartosIstvan](https://discourse.nodered.org/u/BartosIstvan)\
**Post date:** [27 May 2019 14:44 UTC](https://discourse.nodered.org/t/http-get-socket-hang-up/11603/7 "2019-05-27T14:44:38Z")

</div>

Sorry, this one should be the actual

---

<div class="post-metadata">

**Author:** ![BartosIstvan](https://avatars.discourse-cdn.com/v4/letter/b/ecd19e/32.png) [@BartosIstvan](https://discourse.nodered.org/u/BartosIstvan)\
**Post date:** [27 May 2019 15:01 UTC](https://discourse.nodered.org/t/http-get-socket-hang-up/11603/8 "2019-05-27T15:01:20Z")

</div>

```auto
[{"id":"aaaed146.84448","type":"inject","z":"af66aab4.ccac18","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":189,"y":521,"wires":[["66d11064.8fde8"]]},{"id":"fd84bd47.81a15","type":"http request","z":"af66aab4.ccac18","name":"GET from API","method":"GET","ret":"txt","url":"http://192.168.200.112:60736/api/Device","tls":"","x":715,"y":515,"wires":[["4d2ca3ad.a559cc"]]},{"id":"66d11064.8fde8","type":"function","z":"af66aab4.ccac18","name":"set payload and headers","func":"msg.headers = {};\nmsg.headers={ \n 'my_Token': '123456789',\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":409,"y":520,"wires":[["243ecf40.745f4"]]},{"id":"4d2ca3ad.a559cc","type":"debug","z":"af66aab4.ccac18","name":"","active":false,"console":"false","complete":"false","x":942,"y":515,"wires":[]},{"id":"243ecf40.745f4","type":"change","z":"af66aab4.ccac18","name":"header","rules":[{"t":"set","p":"headers","pt":"msg","to":"123456789","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":573.5,"y":436,"wires":[["fd84bd47.81a15"]]}]

```

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [27 May 2019 15:17 UTC](https://discourse.nodered.org/t/http-get-socket-hang-up/11603/9 "2019-05-27T15:17:14Z")

</div>

You added a change node after the function node. It happens that the change node is undoing the msg.header. What happens if you just remove the change node ?

---

<div class="post-metadata">

**Author:** ![BartosIstvan](https://avatars.discourse-cdn.com/v4/letter/b/ecd19e/32.png) [@BartosIstvan](https://discourse.nodered.org/u/BartosIstvan)\
**Post date:** [27 May 2019 15:18 UTC](https://discourse.nodered.org/t/http-get-socket-hang-up/11603/10 "2019-05-27T15:18:16Z")

</div>

The first version was like that with the same error.

---

<div class="post-metadata">

**Author:** ![BartosIstvan](https://avatars.discourse-cdn.com/v4/letter/b/ecd19e/32.png) [@BartosIstvan](https://discourse.nodered.org/u/BartosIstvan)\
**Post date:** [27 May 2019 15:22 UTC](https://discourse.nodered.org/t/http-get-socket-hang-up/11603/11 "2019-05-27T15:22:03Z")

</div>

I have 3 big questions

1. If my http.header is in correct form
2. I dont understand that basic authentication where I use it  
3 can be problem that I m trying to send a http request from another device than the device in which is running localy the API?

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [27 May 2019 17:20 UTC](https://discourse.nodered.org/t/http-get-socket-hang-up/11603/12 "2019-05-27T17:20:01Z")

</div>

> [@BartosIstvan](#):
>
> - If my http.header is in correct form
> - I dont understand that basic authentication where I use it

Those are good questions.

This is the code in your function node:

```auto
msg.headers = {};
msg.headers={ 
    'my_Token': '123456789',
};

return msg;

```

If your goal is to configure the Authentication header then this should be rewriten. However I have no idea on how your API works. Based on the first picture you posted, my impression is that you were using postman to send the token as an URL parameter, not as part of the header (but I may be wrong). I don´t use postman (use insomnia instead) but if you have a way to show better how do you manage to make it work with postman then, perhaps, someone will be able to understand and provide some suggestion.
