Making Cross Site Asynchronous HTTP Post from GWT Client

删除回忆录丶 提交于 2019-12-23 23:52:54

问题


I m working in a GWT based Project and i'm used to making RPC requests alone. I tried creating a new project and making Cross Site request with GWT client using RequestBuilder, but i couldn't get it to work.

I'm not really good with GWT. So Please can anyone tell me how to create a new Project and its settings along with the code for Making Cross site requests from GWT Client(completely removing RPC calls) ..?

I've went through google and stackoverflow, but no complete thing on this topic. It will be really helpful for every one i hope.


回答1:


If you intend in only supporting browsers that support CORS (which, you'll notice, excludes IE, at least until IE10 is released), then you can simply use RequestBuilder or GWT-RPC, like you always did.
If you ever use custom request headers, then the server will have to allow the client application to do those cross-origin requests, by sending back the appropriate Access-Control-Allow-Origin header in response to OPTIONS requests (known as preflight requests in CORS).

If you want/need to support IE, and you have to make a POST request, then you have no other choice but using a FormPanel and using some trick to pass the response back to the client (the easiest is to redirect to a page on the same origin as the GWT app, passing the result in the query-string).

If you can do GETs instead of POSTs, then you can use the JsonpRequestBuilder (and of course adapt your server code to respond with JavaScript)




回答2:


We can make Cross Site requests by setting "Access Control Allow Origin http://myexample.com" in Response Headers. It will make the response accessible by the browser. More information https://developer.mozilla.org/en/http_access_control



来源:https://stackoverflow.com/questions/10910185/making-cross-site-asynchronous-http-post-from-gwt-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!