HTTP/1.0 302 Found error POST request

Hello, I am trying to send collected data formatted as json to an API hosted on Azure.

This is the code I use

GSMClient client;

char url[] = "my-azure.northeurope.cloudapp.azure.com";
char path[] = "/api/store";

void parseData(String dataToSend)
{
  if (client.connect(url, 80))
  {
    client.println("POST http://my-azure.northeurope.cloudapp.azure.com/api/store HTTP/1.0");
    client.println("Content-Type: application/json");
    client.println("User-Agent: Arduino/1.0");
    client.println("Connection: close");
    client.print("Content-Length: ");
    client.println(dataToSend.length());
    client.println("");
    client.println(dataToSend);
  }
  else
  {
    ...
  }
}

The result:

Msg from http 
HTTP/1.0 302 Found
Date: Thu, 27 Jan 2022 22:13:09 GMT
Server: Apache/2.4.41 (Ubuntu)
Cache-Control: private, must-revalidate
Location: http://my-azure.northeurope.cloudapp.azure.com
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 59
pragma: no-cache
expires: -1
Vary: Origin
Content-Length: 446
Connection: close
Content-Type: text/html; charset=UTF-8

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="refresh" content="0;url='http://my-azure.northeurope.cloudapp.azure.com'" />

        <title>Redirecting to http://my-azure.northeurope.cloudapp.azure.com</title>
    </head>
    <body>
        Redirecting to <a href="http://my-azure.northeurope.cloudapp.azure.com">http://my-azure.northeurope.cloudapp.azure.com</a>.
    </body>
</html>

However if I try the same post in Postman or use a url of an API not hosted on Azure it works... Anyone has an idea?

Thank alot!

It looks like it is redirecting:
http://my-azure.northeurope.cloudapp.azure.com
to
http://myazure.northeurope.cloudapp.azure.com

Maybe you should take the '-' out of "my-azure" and see if that helps.

Oh, that's a typo from me. I masked the real url with my-azure.northeurope.azure.com.

The '302' status is telling you that you should try the operation again with the URL in the "location" header.

But it is the exact same URL as the given one.

Are you sure, you can access that website via HTTP (port 80)?
If there is HSTS mechanism on webserver, it can force-redirect you via HTTP 302 to HTTPS version of webpage, if you want to access it via HTTP.

Are you sure this is correct?

Normally the request looks like POST /api/store HTTP/1.0 (without the http:// and host name).

Also, many servers like to see a Host: request header since they serve up multiple sites, so you have to tell it which host to serve up.

Solution: There was something wrong with my API. The validation rule failed the whole time, so by updating this rule it worked!