2012-01-07 3 views
0

GWTからのクロスドメインコールの作成方法は? 解決策としてJSONPRequestBuilderが見つかりましたが、POSTではなくGETリクエストのみを作成できます。私はgoogleのURLショートナーサービス( "http://goo.gl/api/shorten")に電話をかけようとしています。Crossdomain all from GAE

+0

「gwtから」を意味するのでしょうか?サーブレットではない? –

+0

ええ、GWTから。何か考えですか? – Vivek

+0

私はcom.google.gwt.http.client.RequestBuilderを試しました。 「内部サーバーエラー」com.google.gwt.xhr.client.XMLHttpRequest.create()Lcom/google/gwt/xhr/client/XMLHttpRequestをスローするのに失敗しました。 – Vivek

答えて

0

URLFetchで取得しました。以下は私のコードです:

//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  
1

サーブレットからは、URLFetchで外部httpサービスを呼び出すことができます。

クライアントサイドのGWTから、gwt-google-apis経由でGoogle Shortener APIを直接呼び出すことができます。ページの最後にshortener exampleを参照してください。