Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT JSONP with Post not Get

Tags:

post

jsonp

gwt

I have a web service in the form `http://....../methodName

It returns a jsonp result such as:

methodName(["a":"a", "b":"b"]) 

GWT provides JsonpRequestBuilder class to parse jsonp.

  JsonpRequestBuilder rb = new JsonpRequestBuilder();

  rb.setCallbackParam("callback");

  rb.requestObject("http://...../methodName", new AsyncCallback<TestJS>(){
  ...
});

This structure makes a request to url : "http://...../methodName/?callback=__gwt_jsonp_P0.onSuccess".

My web service returns a callback with methodName not with __gwt_json..... So gwt could not create a JavaScriptObject from that response. Also JsonpRequestBuilder works with GET not POST.

How can I achieve those: Sending requests with POST and modifying GWT's default callback name.

like image 250
user706071 Avatar asked Feb 24 '23 11:02

user706071


1 Answers

JSONP will NOT work with POST. Its not a GWT limitation btw.

JSONP is essentially including a javascript file from your server. So, when you make a JSONP call, a temporary tag is added to the DOM.

Now, a <script> tag can always makes a GET request. That's a browser thing, and GWT cannot do much about it.

If you want to make a cross-domain POST call, you have to chose from one of the following options (and they have nothing to do with GWT)

  • Use Flash plus a crossdomain.xml that allows cross domain posts
  • Use Cross Origin Resource Sharing, or CORS. NOTE that this is only supported in modern browsers
  • Use a proxy server on your domain
like image 129
Sripathi Krishnan Avatar answered Mar 03 '23 08:03

Sripathi Krishnan