javascript - Sending data from an HTTPS page to a localhost server -


i wondering best way send data https webpage loaded in browser server running on localhost be. have solution works both http , https pages, https pages browser output mixed content warning (as should). can bypassed changing browser settings, i'd rather not have users that. javascript loaded in browser through bookmark (not sure if best way it, browser independent):

    function sendlocalpost(player, song) {     var url = "http://localhost:13337/";      $.ajax({         type: "post",         crossdomain: true,         contenttype: "application/json; charset=utf-8",         url: url,         datatype: "json",         data: { 'player': player, 'song': song },         success: function (data) {         }     }); } 

and here important snippets c# server code:

    public webapphandler()     {         // other non-important stuff         listener = new httplistener();         listener.prefixes.add("http://localhost:13337/");     }      public void pollforsongchanges()     {         try         {             listener.start();         }         catch (httplistenerexception)         {             return;         }         while (listener.islistening)         {             var context = listener.getcontext();             processrequest(context);         }         listener.close();     }      public void start()     {         pr = new thread(new threadstart(pollforsongchanges));         pr.start();     } 

there's question saw on stackoverflow has great answer (the accepted one), requires bind ssl certificate application, mean have actual trusted ssl certificate localhost server in order have work out-of-the-box on other computers?

maybe i'm going wrong, wondering if there better way. answers.

@alexeilevenkov, mean this:

    function posttoiframe(data) {         var url = "http://localhost:13337/";         var target = "npiframe";          $('body').append('<form action="' + url + '" method="post" target="' + target + '" id="posttoiframe"></form>');         $.each(data, function (n, v) {             $('#posttoiframe').append('<input type="hidden" name="' + n + '" value="' + v + '" />');         });         $('#posttoiframe').submit().remove();     } 

basically, can't this. because hacking.

but, if can modifiy client's hosts file, route localhost 'yourdomain.com' , generate ssl certificate 'yourdomain.com'.

or can make proxy server(https://targetdomain.com http://localhost) in localhost server.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -