ArduinoHttpClient icon indicating copy to clipboard operation
ArduinoHttpClient copied to clipboard

I'm having problem with https websites

Open gomezramones opened this issue 5 years ago • 7 comments

Hi, I'm trying to stablish communication with a server that uses https but without sucess. I have been striving to login to that server but without success.. This is how I do it

HttpClient http(client1,serverAddress);
const int kNetworkTimeout = 3*1000;
// Number of milliseconds to wait if no data is available before trying again
const int kNetworkDelay = 1000;

void Get_token(){
  http.beginRequest();
  http.post("/api/auth/login","application/json", "");
  http.sendHeader("Authorization","Basic c2XBzaXNfdTpmNFgwXktpVjZKQlEzy");
  http.endRequest()
  
  int statusAuth = http.responseStatusCode();
  String response = http.responseBody();
  Serial.print("Response: ");
  Serial.println(response);
  Serial.print("Status response:");
  Serial.println(statusAuth);
}

void setup(){
  Serial.begin(115200);
  Serial2.begin(115200);
  conexionsim();
  conexionred();
  Get_token();
}

I always receive -3, which is timeout

gomezramones avatar May 24 '20 22:05 gomezramones

I am having the same issue. Its seems like httpClient.connect() is not able to connect to server. I am not sure if I am using the right server address in my code but I have tried with so many different ways but every time i get -3 response

zaindroid avatar Jun 02 '20 13:06 zaindroid

I think the problem is this library doesn't handle https website. You might try with an API to connect to your server and see if the address is ok. I could solve the problem by stablishing communication between my SIM5360 and my server https://... enabling https comunication of my module with AT commands. Although at the beginning it was sending me an 301 error (moved permanently) and it was because this type of module (maybe also de this library) doesn't handle redirected as many api or libraries (like in python)

gomezramones avatar Jun 02 '20 15:06 gomezramones

Hi, try to create your client like that (for standard SSL port 443): HttpClient client = HttpClient(wifi, server, 443);

replace wifi with the network connection you use AND in the case of wifi, create your wifi object instance as SSL like this: WiFiSSLClient wifi;

bricemiramont avatar Jun 23 '20 08:06 bricemiramont

Hi, I have tried that scheme but still the same problem.

On Tue, 23 Jun 2020, 10:45 AM bricemiramont, [email protected] wrote:

Hi, try to create your client like that (for standard SSL port 443): HttpClient client = HttpClient(wifi, server, 443);

replace wifi with the network connection you use AND in the case of wifi, create your wifi object instance as SSL like this: WiFiSSLClient wifi;

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/arduino-libraries/ArduinoHttpClient/issues/87#issuecomment-648001483, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD7O7KKFE7T5APE2NLJ6XYTRYBTTBANCNFSM4NJCL4PA .

zaindroid avatar Jun 23 '20 10:06 zaindroid

What module or chip are you using to connect to the internet? It is imposible to make it work with that statement because Https have to make some certification some staffs that library doesn't do it. If you have a quectec or simcom chip you can enable SSL so the chip carries out all the SSL task

gomezramones avatar Jun 23 '20 14:06 gomezramones

A similar problem occurred with a program that posts to Google Spread Sheet with ESP32. Two steps were required to solve the problem.

  • Use WiFiClientSecure instead of WiFiClient.
  • If CA is not set, call setInsecure function (i.d. client.setInsecure() )

I hope this helps someone.
Thank you.

takkaO avatar Jun 06 '23 23:06 takkaO

I am experiencing some difficulties too with HTTPS connections. I have a self signed certificate and CA.

If I execute openssl verify -CAfile ca.crt 192.168.1.10.crt I get OK.

I use WiFiClientSecure and call setCACert But I always have this error:

[  3896][E][ssl_client.cpp:37] _handle_error(): [start_ssl_client():278]: (-9984) X509 - Certificate verification failed, e.g. CRL, CA or signature check failed
[  3899][E][WiFiClientSecure.cpp:135] connect(): start_ssl_client: -9984

If I use setInsecure everything works fine.

I am investigating this issue.

SergioArrighi avatar Apr 08 '24 08:04 SergioArrighi