Help downloading a file through HTTP?

This is kind of a stupid question, but I’m stumped.

How do I download a file available at an http address via the TCP/IP client?
What I have so far seems to just jump to the end without actually downloading the file.

I’m pretty sure the syntax I’m using for the GET command is wrong, I’m just not sure what to put here.

   int fd = open("/gpsfile", O_RDONLY);
        //do file update
        fd = open("/gpsfile", O_CREAT | O_WRONLY | O_TRUNC);

        TCPClient client;
        uint32_t timeout = millis();
        client.connect("", 80);


        client.println("GET /current_1d.alp");
        uint8_t buf[1024]; 
        int totalbytes = 0;
        int sectionbytes = 0;
        while(client.available()) {
            //download file chunk, track how many bytes downloaded
            sectionbytes =, 1024); 
            totalbytes += sectionbytes;
            //write section
            write(fd, buf, sectionbytes);
            //throw error if file size is too large
            if(totalbytes > 20000) {
                Serial.println("download size limit");
        //close file
        Serial.println("gps file written");

You can have a quick read here to get some info of how a HTTP request should look

or a more technical version

In particular your request is missing the protocol/HTTP version specifier.

1 Like

What ScruffR said. Also, you need a blank line at the end of the request header, so the server knows you’ve finished sending all of the options you are going to before it can send the data.