001    /*
002     * Copyright 2006 Google Inc.
003     * 
004     * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005     * use this file except in compliance with the License. You may obtain a copy of
006     * the License at
007     * 
008     * http://www.apache.org/licenses/LICENSE-2.0
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012     * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013     * License for the specific language governing permissions and limitations under
014     * the License.
015     */
016    package com.google.gwt.user.client;
017    
018    import com.google.gwt.core.client.GWT;
019    import com.google.gwt.user.client.impl.HTTPRequestImpl;
020    
021    /**
022     * This class allows you to make asynchronous HTTP requests to the originating
023     * server.
024     */
025    public class HTTPRequest {
026    
027      private static final HTTPRequestImpl httpRequest = (HTTPRequestImpl) GWT
028        .create(HTTPRequestImpl.class);
029    
030      /**
031       * Makes an asynchronous HTTP POST to a remote server.
032       * 
033       * @param url the absolute url to which the POST data is delivered
034       * @param postData the data to post
035       * @param handler the response handler to be notified when either the request
036       *          fails, or is completed successfully
037       * @return <code>false</code> if the invocation fails to issue
038       */
039      public static boolean asyncPost(String url, String postData,
040          ResponseTextHandler handler) {
041        return httpRequest.asyncPost(url, postData, handler);
042      }
043    
044      /**
045       * Makes an asynchronous HTTP POST to a remote server.
046       * 
047       * @param url the absolute url to which the POST data is delivered
048       * @param postData the data to post
049       * @param handler the response handler to be notified when either the request
050       *          fails, or is completed successfully
051       * @return <code>false</code> if the invocation fails to issue
052       */
053      public static boolean asyncPost(String user, String pwd, String url,
054          String postData, ResponseTextHandler handler) {
055        return httpRequest.asyncPost(user, pwd, url, postData, handler);
056      };
057    
058      /**
059       * Makes an asynchronous HTTP GET to a remote server.
060       * 
061       * @param url the absolute url to GET
062       * @param handler the response handler to be notified when either the request
063       *          fails, or is completed successfully
064       * @return <code>false</code> if the invocation fails to issue
065       */
066      public static boolean asyncGet(String url, ResponseTextHandler handler) {
067        return httpRequest.asyncGet(url, handler);
068      }
069    
070      /**
071       * Makes an asynchronous HTTP GET to a remote server.
072       * 
073       * @param url the absolute url to GET
074       * @param handler the response handler to be notified when either the request
075       *          fails, or is completed successfully
076       * @return <code>false</code> if the invocation fails to issue
077       */
078      public static boolean asyncGet(String user, String pwd, String url,
079          ResponseTextHandler handler) {
080        return httpRequest.asyncGet(user, pwd, url, handler);
081      };
082    }