1

I have a xml document I need to send to a remote server that isn't mine.

I have the url and port number for the remote server, and I've tried to implement the transfer using 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

user1479897
  • 145
  • 2
  • 11

2 Answers2

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?

  • Ok thanks, but how does one send messages then to remote server? Surely there must be a way? I just need to transfer a XML message and get a response from the server. – user1479897 Jun 09 '13 at 16:59
  • Thanks but I've read that already. Since I'm not using JSON, I'm currently trying to find out how to make a proxy. They don't have an example of that on the google webpage. – user1479897 Jun 09 '13 at 18:28
  • You might look into setting up your other server to handle cross origin requests http://www.html5rocks.com/en/tutorials/cors/ – nwilde97 Jun 10 '13 at 03:59
  • I was hoping to avoid doing a big javascript effort, was looking for a java source code solution. But I guess it always comes back to the javascript. – user1479897 Jun 10 '13 at 07:36
0

You might look into setting up your other server to handle Cross-Origin Resource Sharing

nwilde97
  • 111
  • 2