Using "fetch" from http:// site

Hello all (first time contributor here :)!

Is it possible to use “fetch” from an http:// site?

I’m having issues with formulating the correct code in my wix page for being able to pass a “pass phrase” and a “message” to an http:// site and capturing the return of an encrypted representation of that message based on the pass phrase.

My form has basically 2 fields and a button to execute the “fetch”:

  • PassPhrase (input field)

  • Message (textbox field)

I pass that information to an external webpage that will return the encrypted representation of the message.

The external site I’m using is just a “test” site where I have the encryption code written.

I pass it both the password and the message in the URL.

The encrypted result is:
gi63HYhDE21bqPIDS6banS0G2oEUofkE4wWRutdRRNDgsEV+2oulJAVa

My goal is to capture this fetch response and display it in a 3rd field (textbox field).

Here’s my wix code:

var thisMessage = $w( “#textBox1” ).value

var url= “a-valid-http-url?password=” + $w( “#input3” ).value + “&message=” + $w( “#textBox1” ).value

fetch(url, { "method" :  "get" }) 
    .then(httpResponse => httpResponse.text()) 
    .then(text => $w( "#textBox2" ).value = text) 

}

Thanks in advance for any help/direction you can provide.

Hi,

You cannot request HTTP content from a service if your site is an HTTPS site. Invalid requests will cause an error.

To fix the request, you can either use the HTTPS protocol to fetch the requested resources from an HTTPS site or you can turn off SSL on your site to fetch an HTTP resource, but we do not recommend turning off SSL on your site.

Hope this helps!

Dara | Corvid Team

That’s helpful Dara! Thank you! Much appreciated.

Hello again Dara! Ok, I added https:// to the site. Does this code grab the response that is echo’d to the web page from the fetched website? Or is there more complex code that I need to use?

Thanks again for your feedback and assistance.

Hey,

I would recommend following the example from the fetch API here . You will find another good example in a forum post here . Also make sure that you add your fetch code to a .jsw file on the backend and just call the function from the front end.

Hope this helps!

Dara | Corvid Team

AWESOME. Thanks again Dara. Will look at this tonight!