Strange issue with path for POST request


#1

Hi,

I’m really new to using the Particle, so please bear with me.

I’m trying to make a POST request to a server on localhost:5000. I’m using ngrok to have a public IP forward the request.

if (client.connect("http://f3c49c3b.ngrok.io", 80)) { 
        
        Serial.println("connected");
                
        client.println("POST http://f3c49c3b.ngrok.io/api/dispense HTTP/1.1");
        client.println("Host: http://f3c49c3b.ngrok.io");
        client.println("Content-Type: application/json");
        client.print("Content-Length: ");
        client.println(strlen(jsonDataString));
        client.println();
        client.println(jsonDataString);
        client.println();
        client.stop();
    }

This code works for some reason. However, I know that

client.println("POST http://f3c49c3b.ngrok.io/api/dispense HTTP/1.1");

should be

client.println("POST /api/dispense HTTP/1.1");

But it doesn’t work when I do that. Is there something I’m doing wrong in the other parts of the request?

Thanks,
Rishub


#2

The protocol (http://) is not part of the server address and hence should be dropped.


#3

@ScruffR Thank you I’ll try that out