Failed to load resource: net::ERR_SSL_PROTOCOL_ERROR - JavaScript to Spring REST API

Viewed 42

I purchased a cheap VPS that is a Debian OS, I then installed my Spring Boot App, which listens for simple POST requests.

My main website is a HTTPS website, and when I try to communicate via JS to my cheap VPS server I get the error

Failed to load resource: net::ERR_SSL_PROTOCOL_ERROR

I assume it's because my VPS IP is not SSL certified, it's a tomcat server; do I need to adjust my Tomcat settings in order to resolve this problem? I am not sure where to go from here. Any help is appreciated.

TL;DR -

All I am trying to do is perform this line of code, to a REST API that I'm hosting on another server address

$.ajax({
          type: "POST",
          url: "//223.165.6.213:8080/contact-us",
            data: JSON.stringify(data),
            contentType: "application/json; charset=utf-8",
            success: function (response) {
                console.log(response);
            }
        });

It works on Localhost or when I connect to my website via http://{url}, but not when it's on a HTTPS(https://{url}) website.

If you need more information, just let me know. Thanks for reading, hope this is clear enough.

1 Answers
      url: "//223.165.6.213:8080/contact-us",

The // means that the same protocol is used as the including site.

It works ... when I connect to my website via http://{url},

In this case the URL is interpreted as http://223.165.6.213:8080/contact-us, which works fine

... but not when it's on a HTTPS(https://{url}) website.

In this case the URL is interpreted as https://223.165.6.213:8080/contact-us, i.e. HTTPS instead of plain HTTP. While in theory it is possible that a server supports both plain HTTP and HTTPS on the same port (in this case 8080) it is uncommon. Trying to access this domain and port with HTTPS shows that the server is not setup for HTTPS, but it instead returns a plain HTTP error - specifically HTTP status code 400 for Bad request:

$ openssl s_client -connect 223.165.6.213:8080 -debug
...
0000 - 48 54 54 50 2f                                    HTTP/
140588768077632:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:ssl/record/ssl3_record.c:332:
...
0000 - 31 2e 31 20 34 30 30 20-0d 0a 43 6f 6e 74 65 6e   1.1 400 ..Conten
...

In general, it is more common to not expose the server on port 8080 in the first place to the public, but employ the main server as a reverse proxy for some path and thus let the main server to the TLS termination too. How this is configured depends on the server you use.

Related