9 years, 9 months ago.

Why is a simple GET failing with protocol error?

Hi, I am trying to do a simple GET request:

sample

    pc.baud(115200);
    eth.init(); //Use DHCP

    eth.connect();
    pc.printf("IP Address is %s\n", eth.getIPAddress());
        
    //GET data
    pc.printf("\nTrying to fetch page...\n");
    int ret = http.get("http://developer.mbed.org/media/uploads/donatien/hello.txt", str, 256);
    if (!ret)
    {
      pc.printf("Page fetched successfully - read %d characters\n", strlen(str));
      pc.printf("Result: %s\n", str);
    }
    else
    {
        pc.printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
    }

But it's failing with error code 3 (protocol error). Response code is 200.

This is on Freescale FRDM-K64F.

What am I doing wrong?

/M

Question relating to:

A HTTP Client for the mbed networking libraries

1 Answer

9 years, 9 months ago.

I also had problems with this, it was the buffer size for the URL, this was 32 chars. So it failed for any URLs bigger, there is a note about this somewhere. Have a look at my test program (also K64F) and you can see the simple edits I made to the HTTPClient library (look for buf_size) http://developer.mbed.org/users/colinmeikle/code/weather/ and http://developer.mbed.org/users/colinmeikle/code/HTTPClient/file/a0d9edb403e5/HTTPClient.cpp

Accepted Answer

Thank you, it works fine now with your changes applied.

posted by Magnus Johanssson 27 Mar 2015