开发者

GWT Query Service

I am using GWT and I needs to query th开发者_开发知识库is service

"https://www.google.com/accounts/RatePassword?Passwd={0}" which will fetch a response


Just reread the question, if that output came from your own server (which it obviously isn't), something like this would have worked:

RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url));
try {
    builder.sendRequest(null, new RequestCallback() {
        @Override public void onError(Request request, Throwable exception) {
            Window.alert("Error: " + exception.toString());
        }
        @Override public void onResponseReceived(Request request, Response response) {

            Window.alert(response.getStatusText());
            Window.alert("Result="+response.getText());
        }
    });
} catch (RequestException e) {
    Window.alert("ERROR:"+e.getMessage());
}

It won't work requesting directly from a remote server due to SOP (Same Origin Policy) being enforced. The first option is to make the request serverside, maybe cache the results and then make a request to your own server to get the data. Python has an HTMLLib library which will allow you to do exactly this (in case you're running a Python backend), otherwise (for backends in PHP/JAVA/PERL/C++ ... unless they have their own relevant libraries), you'll need to do some manual network programming to open up a connection to that host on port 443 and read back the result.

If you want to make the request directly from GWT and skip the backend complexities, then you'll need to throw in some JSNI goodness which will allow you to write JavaScript inside GWT. I've seen an example in the GWT StockWatcher application where JSNI is being used to read JSON from an external host, maybe use that as your starting point.

The easiest alternative is just to write your own password rating algorithm based on algorithms that are available on the net.

Good luck :-)


Have a look at the com.google.gwt.http.client.Request and com.google.gwt.http.client.RequestBuilder classes, it's used for making HTTP requests and inside the callback function, you can process the result.

Have some sample code at home if you need an example, will update tonight.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜