简体   繁体   中英

How can I send cross site PUT requests through GWT?

I am creating a web application using GAE/GWT. Front end GUI is a web client and the server is a RESTFUL server both running in GAE in different domains.

I am using json with padding to communicate with the server but discovered I won't be able to send a PUT/POST/DELETE request.

My application will be used to mainly used to query data (query: 85% of cases, modify data: 15%). All requests will be authenticated.

I am considering the following options.

1) For querying use JsonpRequestBuilder, for modifying create a proxy in the web client server side and hit the REST service through this proxy. Use GWT RPC to communicate to this proxy.

2) Make every request as a GET request in my REST service (including those that modify data) and use jsonp directly from web client.

I would prefer option 1) but option 2) seems less work to do.

Should 1) be my preferred option ?

Are there any problems with 2) given all my requests will be authenticated. ?

Is there any other easy approach to solve this problem ?

Regards,

Sathya

The simplest solution is to use CORS which allows you to send requests two different origins. But it is not so widely spread (check caniuse ), so if you have to support IE8-9, it will not be enough for you.

In your case I would try to implement dual solution (eg CORS + server proxy). If browser supports CORS - send the request directly to the target server, if it doesn't - send request via proxy.

Sorry to ask but what is the advantage to have your client running on a different domain ? From what I understand your client's server will do nothing ...

If you are not the "owner" of the REST backend, maybe this backend should developp an authorization system for third party applications, like oauth2 .

Then your application can talk backend to backend with a secured connection. You can use scribe to do that on your backend.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM