gasagna / A76XX

Arduino library for the A76XX family of SIMCOM cellular modules, with native MQTT(S), HTTP(S), etc, clients!
MIT License
8 stars 3 forks source link

HTTPS does not work for some sites #1

Closed Moskus closed 1 year ago

Moskus commented 1 year ago

It might be that I'm missing something.

Using the supplied test site, same as on the lilygo repo, worked fine:

const char* server_name   = "vsh.pp.ua";
const char* path          = "TinyGSM/logo.txt";
const int   server_port   = 443;
const bool  use_ssl       = true;

However, using other SSL protected sites, like httpbin.org for testing, does not:

const char* server_name   = "httpbin.org";
const char* path          = "get?parameter1=response1;

...gives errors:

Get resource  ... AT+HTTPPARA="URL","https://httbin.org:443/get?parameter1=Response1"

OK
AT+HTTPPARA="USERDATA","User-Agent:A7608E-test/0.0.1"

OK
AT+HTTPACTION=0

OK

+HTTPACTION: 0,715,0Done
AT+HTTPHEAD

ERROR
Failed to read header. Code: -2
AT+HTTPREAD=0,0

ERROR
Failed to read body. Code: -2
Received: 715

Header
----------

Body
----------

Stopping HTTP service ... AT+HTTPTERM

OK
done

What did expect was something like this (using cUrl):

{
  "args": {
    "parameter1": "response1"
  },
  "headers": {
    "Accept": "*/*",
    "Host": "httpbin.org",
    "User-Agent": "curl/8.0.1",
    "X-Amzn-Trace-Id": "Root=1-650ff1f5-55b2627229c72fdf377fa71b"
  },
  "origin": "***removed***",
  "url": "https://httpbin.org/get?parameter1=Response1"
}

There's a 97% chance I'm doing something wrong, but what? It could be that I'm missing a header content-type, but I can't figure out how to set that (and I tested cUrl without that header too).

Moskus commented 1 year ago

It turns out, to noones surprise, that I got it wrong. The reason I couldn't get httpbin.org to work, was a spelling error. 😥

However, one problem remains: I'm trying to get to a server that has a rewrite rule for HTTP to HTTPS traffic. HTTP returns 301 and in a browser I would then get redirected automatically to the HTTPS connection. If I specify https directly, I access the page directly.

However, when I try to do the same using this wonderful library, I only get the 301 response.

HTTPACTION: 0,301,0Done
AT+HTTPHEAD

+HTTPHEAD: 199
HTTP/1.1 301 Moved Permanently
Date: Sun, 24 Sep 2023 09:40:09 GMT
Server: Apache/2.4.57
Location: https://mypage.no/input/
Content-Length: 239
Content-Type: text/html; charset=iso-8859-1
OK
AT+HTTPREAD=0,0

ERROR
Failed to read body. Code: -2
Received: 301

Header
----------
HTTP/1.1 301 Moved Permanently
Date: Sun, 24 Sep 2023 09:40:09 GMT
Server: Apache/2.4.57
Location: https://mypage.no/input/
Content-Length: 239
Content-Type: text/html; charset=iso-8859-1

Body
----------

Stopping HTTP service ... AT+HTTPTERM

It could be a misconfiguration of the web server, I'll have to look into that. But to me it looks like the client is trying http, and not https.

gasagna commented 1 year ago

Hi @Moskus, thank you for using my library. I think this issue is really the fault of the built-in http client provided in the simcom module's firmware. I do not have control over it, nor I do recall redirection being mentioned in the AT command manual.

I have two thoughts. First, you might investigate this error in some other forums. The other thought is: can you not directly send your request to the https server, avoiding the redirection?

Moskus commented 1 year ago

Again, the fault was mine. It turned out that "https://mypage.no/input" redirected to "https://mypage.no/input/" (notice the trailing slash). Using the latter URL worked fine.

Thank you for this wonderful library! I can finally use my A7608 modem with SSL. 💯

pierrechannel commented 6 months ago

i get the same error here on i got this Waiting for modem ... OK Waiting for modem to register on network ... done Connecting ... connected Starting client ... error... code: -2

gasagna commented 6 months ago

Hi @pierrechannel, Can you open a new issue? This will make it easier to help you. Thanks