1

I am writing a test JSP-Servlet page that calls an HTTP API. But when I run the call in Chrome browser it is converting the call to HTTPS and the call fails. The API is not mine and the developer of the API insists that the call has to be on HTTP.

So is there a way to allow this API call using HTTP and prevent Chrome from converting it to an HTTPS call?

Note: I checked the Web and all are saying to change the browser settings. But we will not be able to tell each and every user of our site to do so!

Sam Joshua
  • 310
  • 6
  • 17
Natraj
  • 397
  • 4
  • 9
  • 35
  • Will this help you? https://stackoverflow.com/a/28586593/15590269 – Sam Joshua Jun 15 '21 at 06:29
  • For development this will help me but, when deployed we cannot say to each and every end user to make this changes in desktop / mobile Chrome browser settings to use our API. – Natraj Jun 16 '21 at 07:24

1 Answers1

0

Add this Script on top of your JSP File!

<script>
if (location.protocol == "https:") {
    location.protocol = "http:";
</script>

Note: First, location.protocol checks Url and the second location.protocol will change it to http.

This will redirect your Client. If he visits your website as https: it will redirect him as http:

Sam Joshua
  • 310
  • 6
  • 17