arduino-libraries / ArduinoHttpClient

Arduino HTTP Client library
288 stars 171 forks source link

I'm having problem with https websites #87

Open gomezramones opened 4 years ago

gomezramones commented 4 years ago

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

zaindroid commented 4 years ago

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

gomezramones commented 4 years ago

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)

bricemiramont commented 4 years ago

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;

zaindroid commented 4 years ago

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

On Tue, 23 Jun 2020, 10:45 AM bricemiramont, notifications@github.com 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 .

gomezramones commented 4 years ago

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

takkaO commented 1 year ago

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

I hope this helps someone.
Thank you.

SergioArrighi commented 7 months ago

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.