To main page | Opera Unite HowTo'sHTTP Connections (AJAX/REST)Required step in config.xml ("Enabling network access"): Add 'network="public private"' part to config.xml: <widget network="public private">Otherwise you would get Security violation. get_http(url)function get_http(url) { xmlhttp = new XMLHttpRequest(); xmlhttp.open('GET', url, false); xmlhttp.send(null); if(xmlhttp.status == 200) { return (xmlhttp.responseText); }; return ""; };Now you can do: var html_source = get_http('http://unitehowto.com');This is a request that is done synchronously (i.e. without a callback). Your external IP (async example, with callback)Request (this shows you your external IP by scraping showmyip.com →):function start_page(r) { var req = new XMLHttpRequest(); req.onreadystatechange = function(x) { if (this.readyState == 4) { if(this.status == 200) { widget.showNotification('Your IP:' + this.responseText.match(/displaycopy\("([0-9\.]+)/i)[1]); } } }; req.open('GET', 'http://showmyip.com'); req.send(null); }; Scraping is done for demo purposes only. It's not very good (moral) thing to do and can get you banned from services. Unless you do config.xml thing - any combination of 127.0.0.1, localhost, device.login.operaunite.com, and no port, 80 port, 8840 ports would yield "Security violation" exception. This solves exception for both localhost (private) and remote (www....) addresses. If you modify active (already loaded into Opera) config.xml you might need to delete service, restart Opera and re-install service (config.xml seems to be heavily cached). The answer was found here → and here →. Although this talks about Widgets, turns out it's about Unite too. | Last updated
|