# Curl POST command returns a 404 but 'http request' POST returns a 200

**URL:** <https://discourse.nodered.org/t/curl-post-command-returns-a-404-but-http-request-post-returns-a-200/81727>\
**Category:** General\
**Created:** [2 October 2023 17:25 UTC](https://discourse.nodered.org/t/curl-post-command-returns-a-404-but-http-request-post-returns-a-200/81727 "2023-10-02T17:25:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [2 October 2023 17:25 UTC](https://discourse.nodered.org/t/curl-post-command-returns-a-404-but-http-request-post-returns-a-200/81727/1 "2023-10-02T17:25:20Z")

</div>

BACKGROUND:  
I'm playing with ticktickDB (a time series database) which I have installed and running on a PI 2 model B (I've documented the install process but not posted it yet) and tying to get it to work with NR.

While trying to get it to work in NR I ran into a problem: no data was being saved. I'm using an `http request` node to send (POST) the data to the DB but ran into a problem. The data wasn't being posted but I kept getting a 200 as the return code.

```auto
{
  "time2": 1696264444,
  "payload": "",
  "put": "d 'put pressure 1696264444 1012 location=Office'",
  "_msgid": "c1c28e0c17edfccb",
  "statusCode": 200,
  "headers": {
    "content-length": "0",
    "content-type": "text/plain",
    "x-node-red-request-node": "4717b58c"
  },
  "responseUrl": "http://192.168.1.197:6182/api/put",
  "redirectList": [
  ],
  "retry": 0
}

```

When I used an `http request` node to send the data I got a 404:

```auto
* Trying 192.168.1.197:6182...
* Connected to 192.168.1.197 (192.168.1.197) port 6182 (#0)
> GET /api/put HTTP/1.1
> Host: 192.168.1.197:6182
> User-Agent: curl/7.74.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 404 Not Found
< Content-Length: 0
< Content-Type: text/plain
< 
* Connection #0 to host 192.168.1.197 left intact
* Could not resolve host: d
* Closing connection 1
curl: (6) Could not resolve host: d
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL

```

After a lot of hair pulling, I discovered the issue, a missing`-` (!&@^#%) I was sending:  
`d 'put pressure 1696264444 1012 location=Office'`  
but it needed to be (note the added '-' at the beginning)  
`-d 'put pressure 1696264444 1012 location=Office'`

Shouldn't the `http request` node be returning a 404?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [2 October 2023 17:40 UTC](https://discourse.nodered.org/t/curl-post-command-returns-a-404-but-http-request-post-returns-a-200/81727/2 "2023-10-02T17:40:07Z")

</div>

> [@zenofmud](#):
>
> Shouldn't the `http request` node be returning a 404?

No. the `-d` tells curl "the next bit is **d** ata" - without it (depending on how the curl was structured) it was probably trying to access a server with the address `d`  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/4/c497727f830f94b2c1a319931619d1b8973c5698.png)

Where as in Node-RED, the payload **IS** data (the `-d` is implicit / not required). The fact the `d` was present in the payload is imaterial (and up to the server to reject it with a suitable error - if the server cared enough or was strict enough about the "d" in the payload you would have (probably) gotten a [`400 Bad Request`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [2 October 2023 17:53 UTC](https://discourse.nodered.org/t/curl-post-command-returns-a-404-but-http-request-post-returns-a-200/81727/3 "2023-10-02T17:53:38Z")

</div>

Well that's good to know but I still think it should have returned something other than a 200. If I run the curl without the dash I get the 404 Not Found.

So shouldn't node-red catch it as an error?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [2 October 2023 17:56 UTC](https://discourse.nodered.org/t/curl-post-command-returns-a-404-but-http-request-post-returns-a-200/81727/4 "2023-10-02T17:56:43Z")

</div>

> [@zenofmud](#):
>
> If I run the curl without the dash I get the 404 Not Found.

404 means "not found" so when you run curl without the `-` it THINKS you want to access URL `"d"` - I.E. curl is trying to access a NON existent end point. In short - your request goes nowhere (because `d` is not an end point)

Try yourself `curl d` - you will get what i did

> [@Steve-Mcl](#):
>
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/4/c497727f830f94b2c1a319931619d1b8973c5698.png)

Node-red succeeds because the URL is correct. It is the end device that responds 200 (nothing to do with Node-RED)

---

<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:** [16 October 2023 17:56 UTC](https://discourse.nodered.org/t/curl-post-command-returns-a-404-but-http-request-post-returns-a-200/81727/5 "2023-10-16T17:56:54Z")

</div>

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