Page created:
Jun 19, 2009 (? ago)
Last modified ? ago
To main page | Opera Unite HowTo's

HTTP 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.

Slava V. [about me]


main page



Last updated


  1. Markuper (HTML templates)
  2. .ua
  3. Opera Unite HowTo's
  4. .us (files)
  5. Distribute Your Application
  6. 24/7 sites (permanent applications - idea) [stub]
  7. Issues
  8. HTTP Connections (AJAX/REST)
  9. Cookies
  10. file_wrap.js - File Wrapper
  11. Basic HowTo: Simple app (tutorial)
  12. Static images, client-side scripts
  13. Application Examples
  14. How to Debug Opera Unite apps
  15. Persistence & databases
  16. Opera Unite benchmark
  17. From PHP to Opera Unite
  18. Uniteness (Framework)
  19. Config.xml
  20. Key-value storage
  21. Widget Object
  22. Notifications (Growl'esque)
  23. Reset (debug)
  24. Cron example
  25. What I meant by CNAMEs
  26. Wish List
  27. Device Unavailable
  28. StopLorem (Opera Unite blogging)
  29. uniteness-0.11
  30. GET/POST data
  31. CRUD And Static (example)
  32. Opera object
  33. URLs
  34. Headers & Redirects
  35. Error Console
  36. JSON State (storing data)
  37. Security
  38. /storage/ (in fileio)
  39. Yusef library
  40. unite_info (a-la php_info)
  41. Javascript Imports
  42. onunload / _close
  43. fileio: Sandboxed Filesystem
  44. Request Hierarchy (like php_info)
  45. Intro: Web Apps with Opera Unite