9 years ago.

Getting errors on Fetch

Getting error on HTTP Get. From the source code, I only changed line 14 which is setting the APN.

All the initialization modem commands seem to work fine. I do get an IP address assigned as expected.

Code Section............

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

But then i get the following error messages...

"Trying to fetch page...
Error - ret = 3 - HTTP return code = 301
Trying to post data...
Error - ret = 3 - HTTP return code = 200
Trying to put resource...
Error - ret = 3 - HTTP return code = 200
Trying to delete resource...
Error - ret = 3 - HTTP return code = 200"

Any suggestions on how I debug at this point?

Question relating to:

I've taken the liberty of putting some <<code>> tags in your question to make it a little more readable.

posted by Stephen Paulger 15 May 2015

1 Answer

9 years ago.

mbed.org is returning a 301 which is redirecting you to the same path on developer.mbed.org.

developer.mbed.org also is redirecting from http to https.

You might need to find a different file to test with.

So based on your answer, I changed the URL of the GET to my own server and got that step working fine. But what about the POST? The SW is attempting to POST to httpbin.org. That shouldn't be redirecting to https.

messages... Trying to post data... Error - ret = 3 - HTTP return code = 200

posted by Marvin Fuller 14 May 2015

I would have thought if the HTTP response is a 200 that would mean the request was successful. In the HTTPClient library on line 21 there is a #if that if you change the 0 to a 1 it will give you more debug output. That might help narrow down the cause of the problem.

posted by Stephen Paulger 15 May 2015