简体   繁体   English

GWT发送到远程服务器?

[英]GWT send to remote server?

I have a xml document I need to send to a remote server that isn't mine. 我有一个XML文档,需要发送到不是我的远程服务器。

I have the url and port number for the remote server, and I've tried to implement the transfer using RequestBuilder. 我有远程服务器的URL和端口号,并且我尝试使用RequestBuilder进行传输。

Code Example: 代码示例:

RequestBuilder req= new RequestBuilder(RequestBuilder.POST, URL.encode(url));

req.setHeader("Content-Type", "application/x-www-form-urlencoded");
Request response = 
    req.sendRequest(message, new RequestCallback() {
       public void onError(Request request, Throwable exception) {  
           exception.printStackTrace();
       }
       public void onResponseReceived(Request request, Response response){    
           System.err.println(response.getText());    
       }
    });
} catch (RequestException e) {    
    Window.alert("Failed to send the request: " + e.getMessage());    
}

If this isn't the way to do it, it would be greatly appreciated if anyone could explain what must be done. 如果这不是做到这一点的方式,那么如果有人可以解释必须做的事情,将不胜感激。

Btw the error I'm getting is: 顺便说一句我得到的错误是:

Failed to send the request: The URL www.test.net:8909 is invalid or violates the same-origin security restriction 无法发送请求:URL www.test.net:8909无效或违反了同源安全限制

Simply stated, the Same Origin Policy states that JavaScript code running on a web page may not interact with any resource not originating from the same web site. 简而言之,“相同来源策略”指出,在网页上运行的JavaScript代码可能不会与任何不是来自同一网站的资源进行交互。 The reason this security policy exists is to prevent malicious web coders from creating pages that steal web users' information or compromise their privacy. 存在此安全策略的原因是为了防止恶意Web编码人员创建窃取Web用户信息或损害其隐私的页面。 While very necessary, this policy also has the side effect of making web developers' lives difficult. 虽然非常必要,但此政策还具有使Web开发人员的生活变得困难的副作用。

You can see more on the next link, 您可以在下一个链接中看到更多信息,

https://developers.google.com/web-toolkit/doc/latest/FAQ_Server#What_is_the_Same_Origin_Policy,_and_how_does_it_affect_GWT ? https://developers.google.com/web-toolkit/doc/latest/FAQ_Server#What_is_the_Same_Origin_Policy,_and_how_does_it_affect_GWT吗?

您可能会考虑设置其他服务器来处理跨域资源共享

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

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