instanceofMA / arduino-fetch

High level HTTP Request Library that gives a javascript fetch like API.
GNU General Public License v3.0
78 stars 11 forks source link

Question, HTTPS issue #3

Closed ryanballa closed 2 years ago

ryanballa commented 2 years ago

Hi, I cannot seem to get my code working with HTTPS. It will just print out dots instead of any response. Any help would be appreciated.

RequestOptions options;

    Headers headers;

    headers.contentType = "application/json";
    headers.connection = "keep-alive";
    headers.authkey = "foxtrot%LovesAPIs2022!";

    options.method = "GET";
    options.fingerprint = "C6 D5 5E A8 A5 B0 47 41 E5 A6 62 58 B5 B1 4B 64 E8 39 30 DF";

    Response response = fetch("https://foxtrot-mixpanel-api.herokuapp.com/", options);

    // Printing response body as plain text.
    Serial.println();
    Serial.println(response.statusText);
    Serial.println(response.text());
instanceofMA commented 2 years ago

Which board are you using?

ryanballa commented 2 years ago

Which board are you using?

I'm using the ESP8266 NodeMCU CP2102 ESP-12E

instanceofMA commented 2 years ago

I'm really sorry for not responding earlier. I just noticed an issue so small in your code I'm embarrassed I could have helped you earlier, I apologize!

You are storing headers in a separate Headers object:

    RequestOptions options;

    Headers headers;

    headers.contentType = "application/json";
    headers.connection = "keep-alive";
    headers.authkey = "foxtrot%LovesAPIs2022!";

You do not need that. options.headers is where you should add your headers:

    RequestOptions options;

    options.headers.contentType = "application/json";
    options.headers.connection = "keep-alive";
    options.headers.authkey = "foxtrot%LovesAPIs2022!";

OR you could have done is add this line before fetching in your original code:

options.headers = headers;

This would send your headers with the request. Your original code is saving your headers in your headers object but not adding it to the request options.

I hope this solves your issue. And can you suggest any change in documentation that will clarify things for other people so they don't repeat this mistake?