Show TOC Start of Content Area

This graphic is explained in the accompanying text Simple Get Request to a Specified Host and Port Example  Locate the document in its SAP Library structure

/*

 * Copyright (c) 2006 by SAP AG, Walldorf.,

 * url: http://www.sap.com

 * All rights reserved.

 *

 * This software is the confidential and proprietary information

 * of SAP AG, Walldorf. You shall not disclose such Confidential

 * Information and shall use it only in accordance with the terms

 * of the license agreement you entered into with SAP.

 */

import com.sap.httpclient.HttpClient;

import com.sap.httpclient.HostConfiguration;

import com.sap.httpclient.http.methods.GET;

 

/**

 * This example makes a direct get request to a specified host & port, and

 * prints the response

 *

 */

public class SimpleExample1 {

   public static void main(String[] args) {

      try {

         // getting the host and port from the arguments

         String host = args[0];

         int port = Integer.parseInt(args[1]);

 

         // creating the host configuration

         HostConfiguration hostConfig = new HostConfiguration(host, port);

 

         // creating the http client instance

         HttpClient client = new HttpClient();

 

         // setting the host configuration to the client

         client.setHostConfiguration(hostConfig);

 

         // creating the get method instance

         GET httpGet = new GET();

 

         try {

            // executing the method

            client.executeMethod(httpGet);

 

            // showing the response

            System.out.println("RESPONSE : ");

            System.out.println(httpGet.getResponseBodyAsString());

         } finally { // we will not use the
                     // connection any more so we release it

            httpGet.releaseConnection();

         }

      } catch (Exception e) {

         e.printStackTrace();

         System.out.println("USSAGE : java SimpleExample1 <http host> <http port>");

      }

   }

}

 

End of Content Area