We have received some questions regarding the w3inet.pas unit that ships with the alpha release. Most of the questions is in the line of “why doesn’t this code work” when trying to connect to a server.
The reason you cannot connect to an external host, especially one outside your own domain, is actually a rule imposed on us by the W3C standard (see http://www.w3.org/TR/XMLHttpRequest/ for the documentation). This limitation is called the “same origin” policy, where a website is only allowed to access data and information from the domain it came from. It was this rule that put an effective stop to people stealing content (that was so common in the early days of the Internet).
In other words, you can only use it to access files from your own domain. But, since you are developing on a local machine and not your server this means we have to localize our operations a bit:
- Place the file (an XML file for instance) you want to access in your res or lib folder (add it to your project as a resource)
- use relative paths when accessing it (instead of “http://domain/path/name” use “/res/mystuff.xml”)
- As an alternative, edit your windows host file and point www.yourdomain.com to localhost
Accessing web services
The easiest way to bypass the origin rule is to place your development machine in the domain you want to target, or simply add a line to your host file (we used to do this with our WebSnap services all the time). If these two options are not possible, simply install a public domain proxy on your development machine so that you can control the source.
Future development
Since we have a built in server in our IDE – this issue will be taken care of. We will have a dialog that allows you to define an external service – and then access that as a call to the local server. But for now, the rules of the game is the same as any JavaScript developer have to deal with.
Hello you can check this link for information to solve this problem.
http://www.w3.org/TR/cors/
looking forward to use your new product.
Best regards
Thanks for the comment. Yes I found this when writing the class and indeed the easiest way is to set the Allow-Origin response header. Both google API’s and Yahoo does this.
Again, thanks for the feedback!