Reputation: 8336
How to make a cross-domain call from GWT? I found JSONPRequestBuilder as a solution, but it can only create GET request not POST. I am trying to call URL shortner service ("http://goo.gl/api/shorten") of google.
Upvotes: 0
Views: 238
Reputation: 8336
Got it through URLFetch. Below is my code:
//Classes to import
import com.google.appengine.api.urlfetch.HTTPMethod;
import com.google.appengine.api.urlfetch.HTTPRequest;
import com.google.appengine.api.urlfetch.HTTPResponse;
import com.google.appengine.api.urlfetch.URLFetchService;
import com.google.appengine.api.urlfetch.URLFetchServiceFactory;
//Shortening download URL
URL url=new URL("http://goo.gl/api/shorten");
HTTPRequest req=new HTTPRequest(url,HTTPMethod.POST);
req.setPayload(("url=www.google.com").getBytes());
URLFetchService service = URLFetchServiceFactory.getURLFetchService();
HTTPResponse response = service.fetch(req);
byte[] content = response.getContent();
String urlshort=new String(content); //here is the JSON data from goo.gl
Upvotes: 0
Reputation: 80330
From servlet on GAE you can call external http services via URLFetch.
From client side GWT you can directly call Google Shortener API via gwt-google-apis. See the shortener example at the end of page.
Upvotes: 1