简体   繁体   中英

How can I make cross-domain requests to a local server from an external page in Opera?

I have a system that's responsible for distributing jobs to a group of browsers running on different machines. Each browser reloads a page waiting for jobs to come in.

One thing each job does is to make a cross-domain JSONP request to a local server running on the local machine in order to get some information from the system. This works in every browser I've tried except for Opera.

Here's the jQuery code that I'm using to make the request:

$.ajax({
  url: "http://10.20.30.40:8000/...",
  dataType: "jsonp",
  data: someData
  success: function(data) { ... }
});

The 10.20.30.40 host is the local IP address, identifying a local server running on the machine with the browser. The page which is making this request is loaded from a domain name like blah.internal.example.com which is visible to all the machines inside our network.

The first such request made from Opera (I'm using 12.02) succeeds. However, subsequent requests made in the same way are never actually made. They don't show up in the network tab of the inspector. In the console, a message is displayed saying Linked script not loaded .

I believe that this message (and the lack of a request) is triggered by Opera's Cross-Network Security, which is described in this blog post . On Stackexchange, this answer suggests a workaround, but it requires user interaction. For my use case, the browsers are started, stopped, and run by a script, so user interaction isn't an option.

Is there a way to disable this cross-network security in Opera completely, or for pages loaded from a particular "trusted" host? I need a change that I can make in the preferences or opera:config that will be sticky across sessions. (All of these computers are running on an internal network on internally controlled pages, so I'm not worried about cross-network attacks.)

Why bother with JSONP, if you can use CORS in Opera 12+ (and every other browser, even IE8)? It works like charm.

Just don't forget to add required Access-Control-Allow-* headers to your local server.

More info at Opera dev network: http://dev.opera.com/articles/view/dom-access-control-using-cross-origin-resource-sharing/

Try disabling the security feature entirely in opera:config#Cross%20Network (seems SO won't let me link to that..)

Naturally, if you have disabled a security feature you should surf cautiously ever after.. ;-)

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