0

I currently have a website running which sends a POST request using AJAX to an IP. It does however not work, as my site is served from HTTPS and the IP is, well..., HTTP. It is due to mixed content. How can I resolve this? I would not like to change my website to use HTTP instead of HTTPS.

Ajax request:

$.ajax({
    type: 'POST',
    url: 'http://' + MYIP,
});

There is a similar question, however, it does not fully answer this question as the answer "use HTTPS" is not possible for an IP (to my knowledge)

EDIT

I have an Arduino that listens to HTTP requests and concatenates them in plain text to form a readable string (E.g. POST /?remote=2 HTTP/). If I am using HTTPS it will not work as the Arduino receives an encrypted post.

One solution is to rewrite the server to let it redirect the specific directory from HTTPS to HTTP, though I have no experience with NGINX rewriting.

Jason
  • 1,658
  • 3
  • 20
  • 51
  • Possible duplicate of [HTTP Ajax Request via HTTPS Page](https://stackoverflow.com/questions/4032104/http-ajax-request-via-https-page) – MrUpsidown Dec 31 '17 at 11:38
  • @MrUpsidown I wish it was, but this is regarding an IP which can't be run on HTTPS (to my knowledge) – Jason Dec 31 '17 at 11:40
  • Are you sure your IP has a valid SSL/TLS certificate? It isn't very common to have that. You can read more [here](https://stackoverflow.com/q/2043617). If you really have a valid certificate, can't you simply change `url: 'http://' + MYIP` to `url: 'https://' + MYIP`? – Ivar Dec 31 '17 at 11:43
  • For my purpose, the IP needs to be HTTP. Maybe I could try to disable HTTPS on a directory – Jason Dec 31 '17 at 11:55
  • You are sending an Ajax request to a server identified by an ip instead of a name. This doesn’t change the situation at all. Set up the destination server to listen on https and you are done. What is the technology for the listening server? – Lelio Faieta Dec 31 '17 at 11:57
  • Btw the server can be listening both on http and https (the ports are different). So you don’t have to choose between the two as you say – Lelio Faieta Dec 31 '17 at 11:59
  • Well, I read the HTTP request into plain text. If I were to read the HTTPS request, it will be encrypted and the device is not powerful enough to decrypt it. – Jason Dec 31 '17 at 11:59
  • To read the plain text what do you use? JavaScript, php or what else? What is the Webserver on the device? Https does not require strong hardware resources. Btw: did you fix the Cors issue you have (as in the question you mentioned btw) – Lelio Faieta Dec 31 '17 at 12:02
  • That's simply not possible. If you send data over http on an https page, then you have mixed content. You might want to consider setting up a proxy. So that you send your POST with https to an other server (possibly the same server as your website is on) and then let the server send it to that ip over http. – Ivar Dec 31 '17 at 12:04
  • I will try to add the whole picture of what I am exactly using it for above – Jason Dec 31 '17 at 12:17

0 Answers0