简体   繁体   中英

Electron GET request from LOCALHOST

I'm trying to GET a response from a web server that I run on Localhost( 127.0.0.1 ), Exactly form this URL: http://127.0.0.1:3125/ping . The request is invoked by an html file that look like this, loaded in an Electron app:

<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js"></script>
</head>
<body>
    <script type="text/javascript">
    $(document).ready(function () {
            $.get( "127.0.0.1:3215/ping", function( data ) {
              console.log( data );
            });
        }
    );
    </script>
</body>
</html>

However using the DevTools(console) while in the app, I can see that the response is always GET http://localhost:3215/ping 404 (NOT FOUND) and if I try to request a page, not in localhost(like http:google.com ), the request is always successful. And even if a try to start the request(on localhost) from my browser console, it is always successful.

I can't understand why electron behaves like this.

You have not specified the protocol you want to use for the request, http:// or https://.

$.get( "http://127.0.0.1:3215/ping", function( data ) {
    console.log( data );
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM