Java – GWT requestbuilder – cross site request
•
Java
I'm trying to create a cross site request using the GWT request builder, but I can't make it work As you can see, this is a sample GWT project that I have completed https://developers.google.com/web-toolkit/doc/latest/tutorial/Xsite. But I still lack something
I publish the code here What did I miss?
package com.gwt.reqbuilder.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.google.gwt.http.client.URL;
import com.google.gwt.user.client.Window;
public class GWTRequestBuilder implements EntryPoint
{
private static final String JSON_URL = "http://localhost:8000/?q=ABC&callback=callback125";
public void onModuleLoad()
{
GWTPOSTHTTP();
}
public void GWTPOSTHTTP()
{
String postUrl="http://localhost:8000";
String requestData="q=ABC&callback=callback125";
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,postUrl);
try {
builder.sendRequest(requestData.toString(),new RequestCallback()
{
public void onError(Request request,Throwable e)
{
Window.alert(e.getMessage());
}
public void onResponseReceived(Request request,Response response)
{
if (200 == response.getStatusCode())
{
Window.alert(response.getText());
} else {
Window.alert("Received HTTP status code other than 200 : "+ response.getStatusText());
}
}
});
} catch (RequestException e) {
// Couldn't connect to server
Window.alert(e.getMessage());
}
}
}
Solution
In fact, if we can set it in the servlet response header, we can issue cross site requests from GWT requestbuilder
Response.setHeader("Access-Control-Allow-Origin","http://myhttpserver");
It's cool. If someone needs GWT project and python servlet, please let me know and I can upload files
GWT Client Code : https://github.com/manikandaraj/MLabs/tree/master/GWT/GWTClient
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
