Cross Site XML-HTTP?

15 views
Skip to first unread message

Quu

unread,
Jun 11, 2010, 4:02:36 PM6/11/10
to Google Web Toolkit
I want to, inside of my GWT application, load an XML document from a
different server then where the base page is from. My page is on
server A, and the GWT compiled javascript is on a different server,
location B. The XML I am trying to read is at the same location, B, so
why can't the JS loaded from there access ti with out tripping the SOP
error?.

I used to be able to load XML from a remote site as long as the .html
file hosting the GWT app had a link to an image from the same location
as the XML. This worked in at least 1.7 of GWT, though I suspect it is
more the fact that I have a newer web browser since then.

I have looked at http://code.google.com/webtoolkit/doc/latest/tutorial/Xsite.html
and I don't think I can specifically use any of the tricks there. They
seam to be JSON specific, and require a smart backend to append the
callback to the JSON returned text.

KeremTiryaki

unread,
Jun 12, 2010, 7:36:40 PM6/12/10
to Google Web Toolkit
I think you should check here:https://developer.mozilla.org/En/
HTTP_access_control
because you can not make a request to other domains directly.
There are some method to overcome this kind of problems.
iframe : http://developer.apple.com/internet/webcontent/iframe.html
JSONP : http://code.google.com/webtoolkit/doc/latest/tutorial/Xsite.html
and I have heard something about hidden image but i did not found any
document about it.

On Jun 11, 11:02 pm, Quu <otakuvi...@gmail.com> wrote:
> I want to, inside of my GWT application, load an XML document from a
> different server then where the base page is from. My page is on
> server A, and the GWT compiled javascript is on a different server,
> location B. The XML I am trying to read is at the same location, B, so
> why can't the JS loaded from there access ti with out tripping the SOP
> error?.
>
> I used to be able to load XML from a remote site as long as the .html
> file hosting the GWT app had a link to an image from the same location
> as the XML. This worked in at least 1.7 of GWT, though I suspect it is
> more the fact that I have a newer web browser since then.
>
> I have looked athttp://code.google.com/webtoolkit/doc/latest/tutorial/Xsite.html

Sky

unread,
Jun 12, 2010, 7:47:12 PM6/12/10
to Google Web Toolkit
You must have had a very old browser indeed to have been able to load
XML from a different server than what is in the browser's address bar
(which is the factor that determines whether a call triggers SOP or
not... it's always fine to set the src or anything (such as <script>
elements) to something from a different domain, but doing an
HTTPXMLRequest ONLY works for the same domain as the website you have
loaded.

The ONLY 2 solutions are the ones on the page you referenced. A proxy
on your server will always work, but it's slow because the data makes
two trips instead of one. If it isn't a small amount of data maybe
that won't matter for your situation?

Really the best option is to use JSON. Is there any particular reason
you cannot use JSON? You are correct that you need to use JSONP and
put the XML data inside a callback function. So you can't use a
service on server B that will ONLY send the XML. Don't you have access
to and the ability to add code to the app running on server B? All you
need to do is add another service that calls the original service and
pads it with the callback function.

Cake! ^_^

But seriously, these are the only 2 options you have; there is no
other hack unless you force your users to use an incredibly ancient
browser.

cheers

On Jun 11, 3:02 pm, Quu <otakuvi...@gmail.com> wrote:
> I want to, inside of my GWT application, load an XML document from a
> different server then where the base page is from. My page is on
> server A, and the GWT compiled javascript is on a different server,
> location B. The XML I am trying to read is at the same location, B, so
> why can't the JS loaded from there access ti with out tripping the SOP
> error?.
>
> I used to be able to load XML from a remote site as long as the .html
> file hosting the GWT app had a link to an image from the same location
> as the XML. This worked in at least 1.7 of GWT, though I suspect it is
> more the fact that I have a newer web browser since then.
>
> I have looked athttp://code.google.com/webtoolkit/doc/latest/tutorial/Xsite.html

Sky

unread,
Jun 12, 2010, 8:04:04 PM6/12/10
to Google Web Toolkit
The iframe method mentioned above by Kerem won't work for cross site
scripting. That's only useful for doing callbacks to the same server
because the code "window.parent.handleResponse()" being ran by the
iframe won't work since browsers SOP also applies to iframes. If the
src of the iframe is from a different domain, the iframe won't be able
to access any code in the parent frame. That method is just a
convoluted way of doing the exact same thing XMLHTTPRequest does. Both
ways can be used to talk to server A and have server A be a proxy to
server B.

JSONP is the only way to do cross site scripting without a proxy.

cheers.

George Georgovassilis

unread,
Jun 14, 2010, 4:49:10 AM6/14/10
to Google Web Toolkit
Hello Quu,

You obviously control Server B because you load the application from
there. Can you also control server A? In that case you could wrap the
XML with a couple techniques. The iframe technique for example would
wrap the XML into a big javascript string and publish it to your
application, i.e. via the window.name transport. You really will have
to use some kind of javascript here because that is the only way to
comply with the same origin policy: the SOP makes sure that a script
can only get information from a different domain if that domain offers
the data, i.e. by actively exporting it via javascript. Since XML is a
passive document format, it cannot do that.

On Jun 11, 10:02 pm, Quu <otakuvi...@gmail.com> wrote:
> I want to, inside of my GWT application, load an XML document from a
> different server then where the base page is from. My page is on
> server A, and the GWT compiled javascript is on a different server,
> location B. The XML I am trying to read is at the same location, B, so
> why can't the JS loaded from there access ti with out tripping the SOP
> error?.
>
> I used to be able to load XML from a remote site as long as the .html
> file hosting the GWT app had a link to an image from the same location
> as the XML. This worked in at least 1.7 of GWT, though I suspect it is
> more the fact that I have a newer web browser since then.
>
> I have looked athttp://code.google.com/webtoolkit/doc/latest/tutorial/Xsite.html
Reply all
Reply to author
Forward
0 new messages