Java 什么是UseHTTPGetMethod(字符串URI)构造函数

Java 什么是UseHTTPGetMethod(字符串URI)构造函数,java,apache,Java,Apache,我已经从apache.org链接上阅读了关于GetMethod的documnet ,但我没有从中得到足够的东西。有人能给我解释一下这个方法应该在什么时候用一个简单的例子吗 GetMethod(字符串URI)用于创建对URI的HTTP GET请求。下面的例子解释了一切 import org.apache.commons.httpclient.*; import org.apache.commons.httpclient.methods.*; import org.apache.commons.ht

我已经从apache.org链接上阅读了关于GetMethod的documnet ,但我没有从中得到足够的东西。有人能给我解释一下这个方法应该在什么时候用一个简单的例子吗

GetMethod(字符串URI)用于创建对URI的HTTP GET请求。下面的例子解释了一切

import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.params.HttpMethodParams;

import java.io.*;

public class HttpClientTutorial {

  private static String url = "http://www.apache.org/";

  public static void main(String[] args) {
    // Create an instance of HttpClient.
    HttpClient client = new HttpClient();

    // Create a method instance.
    GetMethod method = new GetMethod(url);

    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, 
            new DefaultHttpMethodRetryHandler(3, false));

    try {
      // Execute the method.
      int statusCode = client.executeMethod(method);

      if (statusCode != HttpStatus.SC_OK) {
        System.err.println("Method failed: " + method.getStatusLine());
      }

      // Read the response body.
      byte[] responseBody = method.getResponseBody();

      // Deal with the response.
      // Use caution: ensure correct character encoding and is not binary data
      System.out.println(new String(responseBody));

    } catch (HttpException e) {
      System.err.println("Fatal protocol violation: " + e.getMessage());
      e.printStackTrace();
    } catch (IOException e) {
      System.err.println("Fatal transport error: " + e.getMessage());
      e.printStackTrace();
    } finally {
      // Release the connection.
      method.releaseConnection();
    }  
  }
}

请阅读评论以清楚理解。希望这有助于实际实现HTTP
GET
方法。因此,如果您想向某个URL发送一个HTTP
GET
请求,那么您应该使用它

GetMethod接受HTTP Get请求,其中url是url中显示的查询字符串,例如,当您提交包含用户名和密码的表单时,以及点击登录url时的操作,url将显示为

http://[application name]/login?userName=prawin&password=123

-建议您使用发送机密信息的帖子。
谢谢。

你能给我解释一下这些语句吗GetMethod=newgetMethod(url);//提供自定义重试处理程序是必需的方法。getParams().setParameter(HttpMethodParams.retry_处理程序,新的默认HttpMethodRetryHandler(3,false));尝试{//Execute the method.int statusCode=client.executeMethod(method);method.getParams()以HttpMethodParams对象的形式返回与此方法关联的HttpProtocol参数。我们正在将属性RETRY_处理程序设置为DefaultHttpMethodRetryHandler(3,false))retryCount为3,requestSentRetryEnabled为false。只需阅读文档HttpMethodParams和DefaultHttpMethodRetryHandler,就会有所帮助。