# Use the HTTP-Request to recreate an curl command

**URL:** <https://discourse.nodered.org/t/use-the-http-request-to-recreate-an-curl-command/76619>\
**Category:** General\
**Created:** [16 March 2023 10:32 UTC](https://discourse.nodered.org/t/use-the-http-request-to-recreate-an-curl-command/76619 "2023-03-16T10:32:00Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![SteveRed](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@SteveRed](https://discourse.nodered.org/u/SteveRed)\
**Post date:** [16 March 2023 10:32 UTC](https://discourse.nodered.org/t/use-the-http-request-to-recreate-an-curl-command/76619/1 "2023-03-16T10:32:00Z")

</div>

Hello, i am trying since 2h and cant find an working solution.

I try to build the following command with the nodered http-request:

curl -d "otpType=ReadRealTimeData&pwd=PASSWD" -X POST [http://5.8.8.8](http://5.8.8.8)

Can anybody help me?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [16 March 2023 10:47 UTC](https://discourse.nodered.org/t/use-the-http-request-to-recreate-an-curl-command/76619/2 "2023-03-16T10:47:35Z")

</div>

Try setting the http request node to  
method `POST`  
url `http://5.8.8.8`  
and feed in payload

```auto
{
"otpType": "ReadRealTimeData",
"pwd": "PASSWD"
}
```

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [16 March 2023 10:54 UTC](https://discourse.nodered.org/t/use-the-http-request-to-recreate-an-curl-command/76619/3 "2023-03-16T10:54:01Z")

</div>

Also need to set the `Content-Type` header to `application/x-www-form-urlencoded`, as it will format it out as JSON I believe

---

<div class="post-metadata">

**Author:** ![SteveRed](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@SteveRed](https://discourse.nodered.org/u/SteveRed)\
**Post date:** [16 March 2023 11:02 UTC](https://discourse.nodered.org/t/use-the-http-request-to-recreate-an-curl-command/76619/4 "2023-03-16T11:02:48Z")

</div>

```auto
[
    {
        "id": "e3d6e970.e7768",
        "type": "inject",
        "z": "581fc531.7fd2ac",
        "name": "",
        "props": [],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 130,
        "y": 860,
        "wires": [
            [
                "fb96465e77051bc0"
            ]
        ]
    },
    {
        "id": "c62fdf0a.1924d8",
        "type": "http request",
        "z": "581fc531.7fd2ac",
        "name": "",
        "method": "POST",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "http://5.8.8.8",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [
            {
                "keyType": "Content-Type",
                "keyValue": "",
                "valueType": "other",
                "valueValue": "application/x-www-form-urlencoded"
            }
        ],
        "x": 470,
        "y": 860,
        "wires": [
            [
                "af8c089c.a6fbe8"
            ]
        ]
    },
    {
        "id": "af8c089c.a6fbe8",
        "type": "debug",
        "z": "581fc531.7fd2ac",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 690,
        "y": 860,
        "wires": []
    },
    {
        "id": "fb96465e77051bc0",
        "type": "function",
        "z": "581fc531.7fd2ac",
        "name": "",
        "func": "msg.payload = {\n \"otpType\": \"ReadRealTimeData\",\n \"pwd\": \"PASSWD\"\n};\n\nreturn msg\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 280,
        "y": 860,
        "wires": [
            [
                "c62fdf0a.1924d8"
            ]
        ]
    }
]

```

This is my first try. But i am getting an error:

"RequestError: socket hang up : [http://5.8.8.8](http://5.8.8.8)"

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [16 March 2023 11:10 UTC](https://discourse.nodered.org/t/use-the-http-request-to-recreate-an-curl-command/76619/5 "2023-03-16T11:10:07Z")

</div>

Try unchecking basic authorization in the http request node

---

<div class="post-metadata">

**Author:** ![SteveRed](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@SteveRed](https://discourse.nodered.org/u/SteveRed)\
**Post date:** [16 March 2023 11:10 UTC](https://discourse.nodered.org/t/use-the-http-request-to-recreate-an-curl-command/76619/6 "2023-03-16T11:10:33Z")

</div>

Corrected the function Node to:

```auto
msg.headers = {
    'Content-Type': 'application/x-www-form-urlencoded'
};

msg.payload = {
    "otpType": "ReadRealTimeData",
    "pwd": "SXK2PXZVEK"
};

return msg

```

But the error is the same.

---

<div class="post-metadata">

**Author:** ![SteveRed](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@SteveRed](https://discourse.nodered.org/u/SteveRed)\
**Post date:** [16 March 2023 11:12 UTC](https://discourse.nodered.org/t/use-the-http-request-to-recreate-an-curl-command/76619/7 "2023-03-16T11:12:32Z")

</div>

> [@E1cid](#):
>
> basic authorization

basic auth. is not set.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [16 March 2023 11:13 UTC](https://discourse.nodered.org/t/use-the-http-request-to-recreate-an-curl-command/76619/8 "2023-03-16T11:13:30Z")

</div>

This works using curl on the same machine as Node RED right?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [16 March 2023 11:15 UTC](https://discourse.nodered.org/t/use-the-http-request-to-recreate-an-curl-command/76619/9 "2023-03-16T11:15:56Z")

</div>

> [@SteveRed](#):
>
> basic auth. is not set.

scratch that must of accidently checked it myself

---

<div class="post-metadata">

**Author:** ![SteveRed](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@SteveRed](https://discourse.nodered.org/u/SteveRed)\
**Post date:** [16 March 2023 11:16 UTC](https://discourse.nodered.org/t/use-the-http-request-to-recreate-an-curl-command/76619/10 "2023-03-16T11:16:54Z")

</div>

yes it works:

```auto
curl -d "optType=ReadRealTimeData&pwd=PASSWD" -X POST http://5.8.8.8
{"sn":"*****","ver":"3.003.02","type":7,"Data":[2321,2331,2332,39,39,40,894,890,919,3307,4459,36,36,1181,1576,5000,5000,5000,2,4573,0,71,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,8,8000,0,29,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,33,0,0,0,0,0,0,0,2679,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"Information":[8.000,7,"****",8,1.22,1.02,1.33,1.02,0.00,1]

```

---

<div class="post-metadata">

**Author:** ![SteveRed](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@SteveRed](https://discourse.nodered.org/u/SteveRed)\
**Post date:** [16 March 2023 11:18 UTC](https://discourse.nodered.org/t/use-the-http-request-to-recreate-an-curl-command/76619/11 "2023-03-16T11:18:39Z")

</div>

no problem, i am happy when someone is trying to help me. I am sitting since hours on this simple task ☹

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [16 March 2023 11:19 UTC](https://discourse.nodered.org/t/use-the-http-request-to-recreate-an-curl-command/76619/12 "2023-03-16T11:19:40Z")

</div>

Just for fun what happens if you enable keep alive?

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/4/744fe3b24029abdf84d66484deb5c1a06f90cb47.png)

I currently cant see any difference between curl and Node RED

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [16 March 2023 11:35 UTC](https://discourse.nodered.org/t/use-the-http-request-to-recreate-an-curl-command/76619/13 "2023-03-16T11:35:19Z")

</div>

The headers differences are here  
the top object is the curl from command line, and lower is a http request from node-red

 ![chrome_screenshot_1678966437356](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/4/b45b4d3344360e015b35103352186e946614b00d.jpeg)

---

<div class="post-metadata">

**Author:** ![SteveRed](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@SteveRed](https://discourse.nodered.org/u/SteveRed)\
**Post date:** [16 March 2023 11:42 UTC](https://discourse.nodered.org/t/use-the-http-request-to-recreate-an-curl-command/76619/14 "2023-03-16T11:42:40Z")

</div>

Yes i captured the HTTP-Headers via tcpdump ant tried to reconfigure the function. My result:

Curl- HTTP-Request

```
POST / HTTP/1.1
Host: 5.8.8.8
User-Agent: curl/7.74.0
Accept: */*
Content-Length: 39
Content-Type: application/x-www-form-urlencoded

optType=ReadRealTimeData&pwd=PASSWD [|http]

```

Nodered- HTTP-Request

```
POST / HTTP/1.1
User-Agent: nodered
Accept: */*
Content-Length: 39
Content-Type: application/x-www-form-urlencoded
Host: 5.8.8.8
Connection: keep-alive

otpType=ReadRealTimeData&pwd=PASSWD [|http]

```

I am still getting an error.

---

<div class="post-metadata">

**Author:** ![cameo69](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cameo69/32/66593_2.png) [@cameo69](https://discourse.nodered.org/u/cameo69)\
**Post date:** [16 March 2023 11:53 UTC](https://discourse.nodered.org/t/use-the-http-request-to-recreate-an-curl-command/76619/15 "2023-03-16T11:53:26Z")

</div>

> [@SteveRed](#):
>
> ```auto
> optType=ReadRealTimeData&pwd=PASSWD [|http]
> 
> ```

vs.

> [@SteveRed](#):
>
> ```auto
> otpType=ReadRealTimeData&pwd=PASSWD [|http]
> 
> ```

?

"opt" vs "otp" ? 🙂

---

<div class="post-metadata">

**Author:** ![SteveRed](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@SteveRed](https://discourse.nodered.org/u/SteveRed)\
**Post date:** [16 March 2023 11:59 UTC](https://discourse.nodered.org/t/use-the-http-request-to-recreate-an-curl-command/76619/16 "2023-03-16T11:59:27Z")

</div>

🤣 that was the error. I think a should take a brake now 😀

---

<div class="post-metadata">

**Author:** ![SteveRed](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@SteveRed](https://discourse.nodered.org/u/SteveRed)\
**Post date:** [16 March 2023 12:03 UTC](https://discourse.nodered.org/t/use-the-http-request-to-recreate-an-curl-command/76619/17 "2023-03-16T12:03:07Z")

</div>

This is the result, thank you all for your time ! 😀

```auto
[
    {
        "id": "6f3b89af5e9fde75",
        "type": "inject",
        "z": "cc21c9460c41635a",
        "name": "",
        "props": [],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 130,
        "y": 960,
        "wires": [
            [
                "aa80346ea031c53f"
            ]
        ]
    },
    {
        "id": "64b0442cd898bef8",
        "type": "http request",
        "z": "cc21c9460c41635a",
        "name": "",
        "method": "POST",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "5.8.8.8",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [
            {
                "keyType": "User-Agent",
                "keyValue": "",
                "valueType": "other",
                "valueValue": "NodeRed"
            },
            {
                "keyType": "Accept-Encoding",
                "keyValue": "",
                "valueType": "other",
                "valueValue": "*/*"
            },
            {
                "keyType": "Content-Type",
                "keyValue": "",
                "valueType": "other",
                "valueValue": "application/x-www-form-urlencoded"
            }
        ],
        "x": 490,
        "y": 960,
        "wires": [
            [
                "399b9fe458f69ad0"
            ]
        ]
    },
    {
        "id": "399b9fe458f69ad0",
        "type": "debug",
        "z": "cc21c9460c41635a",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 690,
        "y": 960,
        "wires": []
    },
    {
        "id": "aa80346ea031c53f",
        "type": "function",
        "z": "cc21c9460c41635a",
        "name": "",
        "func": "msg.payload = {};\nmsg.payload = {\n \"optType\": \"ReadRealTimeData\",\n \"pwd\": \"PASSWD\"\n};\n\nreturn msg\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 300,
        "y": 960,
        "wires": [
            [
                "64b0442cd898bef8"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [16 March 2023 12:03 UTC](https://discourse.nodered.org/t/use-the-http-request-to-recreate-an-curl-command/76619/18 "2023-03-16T12:03:46Z")

</div>

Well spotted @cameo69

@SteveRed  
Can you mark @cameo69's post as the answer - it will remind us to pay more attention in future 😀

---

<div class="post-metadata">

**Author:** ![SteveRed](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@SteveRed](https://discourse.nodered.org/u/SteveRed)\
**Post date:** [16 March 2023 12:05 UTC](https://discourse.nodered.org/t/use-the-http-request-to-recreate-an-curl-command/76619/19 "2023-03-16T12:05:02Z")

</div>

Done. Thank you, this is a good forum. Hope a can help next time an other user. Kind regards.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [30 March 2023 12:05 UTC](https://discourse.nodered.org/t/use-the-http-request-to-recreate-an-curl-command/76619/20 "2023-03-30T12:05:57Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
