简体   繁体   English

如何通过GWT发送跨站点PUT请求?

[英]How can I send cross site PUT requests through GWT?

I am creating a web application using GAE/GWT. 我正在使用GAE / GWT创建一个Web应用程序。 Front end GUI is a web client and the server is a RESTFUL server both running in GAE in different domains. 前端GUI是Web客户端,服务器是RESTFUL服务器,都在不同域的GAE中运行。

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. 我正在使用带有填充的json与服务器进行通信,但是发现我将无法发送PUT / POST / DELETE请求。

My application will be used to mainly used to query data (query: 85% of cases, modify data: 15%). 我的应用程序将主要用于查询数据(查询:85%的情况下,修改数据: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. 1)对于查询,请使用JsonpRequestBuilder进行修改,以便在Web客户端服务器端创建一个代理,然后通过该代理访问REST服务。 Use GWT RPC to communicate to this proxy. 使用GWT RPC与该代理进行通信。

2) Make every request as a GET request in my REST service (including those that modify data) and use jsonp directly from web client. 2)在我的REST服务(包括那些修改数据的请求)中将每个请求作为GET请求发出,并直接从Web客户端使用jsonp。

I would prefer option 1) but option 2) seems less work to do. 我希望选择1),但选择2)的工作似乎较少。

Should 1) be my preferred option ? 1)应该是我的首选吗?

Are there any problems with 2) given all my requests will be authenticated. 2)如果我的所有请求都将通过身份验证,是否有任何问题。 ?

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. 最简单的解决方案是使用CORS ,它允许您发送两个不同来源的请求。 But it is not so widely spread (check caniuse ), so if you have to support IE8-9, it will not be enough for you. 但是它并没有广泛传播(请检查caniuse ),因此,如果您必须支持IE8-9,那么这对于您来说还不够。

In your case I would try to implement dual solution (eg CORS + server proxy). 在您的情况下,我将尝试实现双重解决方案(例如,CORS +服务器代理)。 If browser supports CORS - send the request directly to the target server, if it doesn't - send request via proxy. 如果浏览器支持CORS,则直接将请求发送到目标服务器;如果不支持,则通过代理发送请求。

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 . 如果您不是REST后端的“所有者”,则此后端可能应该为第三方应用程序开发一个授权系统,例如oauth2

Then your application can talk backend to backend with a secured connection. 然后,您的应用程序可以使用安全连接在后端与后端对话。 You can use scribe to do that on your backend. 您可以使用scribe在后端上执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Google App Engine 中允许跨站点源请求? - How to allow cross site origin requests in Google App Engine? 如何使用Sendgrids API发送电子邮件以使用rails 4发送电子邮件? 我似乎把所有的东西放在一起 - How do I send emails using Sendgrids API to send emails with rails 4? I can seem to put all the pieces together 如何在GWT应用程序中发送电子邮件 - How to Send Emails in GWT Application 我正在尝试创建一个登录页面,如何通过我的用户名和密码并将其引导到重定向的网站? - I am trying to make a login page, how can I pass through my username and password and lead it to a redirected site? 如何从非GWT(但Java)gapplication调用服务器上的GWT RPC方法? - How can I call a GWT RPC method on a server from a non GWT (but Java) gapplication? 如何解决此内部GWT编译器错误 - How can I work around this internal GWT compiler error 如何在JavaMail中发送HTML文件? - How can I send an HTML file in JavaMail? 如何将数据发送到Chrome扩展程序? - How can I send data to Chrome extension? 如何在请求中要求 api-token 字段? - How can I require an api-token field on requests? 如何从服务器(appengine)获取日期对象并将其转换为客户端的时区日期(gwt)? - How can I get a date object from server (appengine) and convert it to client's timezone's date (gwt)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM