1

我有一个需要发送到不属于我的远程服务器的 xml 文档。

我有远程服务器的 url 和端口号,我尝试使用 RequestBuilder 实现传输。

代码示例:

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());    
}

如果这不是这样做的方法,如果有人能解释必须做什么,将不胜感激。

顺便说一句,我得到的错误是:

发送请求失败:网址www.test.net:8909无效或违反同源安全限制

4

2 回答 2

0

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. The reason this security policy exists is to prevent malicious web coders from creating pages that steal web users' information or compromise their privacy. While very necessary, this policy also has the side effect of making web developers' lives difficult.

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?

于 2013-06-09T16:50:43.613 回答
0

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

于 2013-06-10T04:02:45.833 回答