设置HttpClient代理以访问EC2上的REST URL

时间:2010-08-12 00:03:00

标签: amazon-ec2 httpclient

我有一个EC2映像正在运行并托管可从URL访问的REST服务。以下是我的所作所为:

  1. ssh -i <ec2-certificate> D port user@ec2-host
  2. 在firefox网络浏览器中设置代理并输入网址http://ec2-host:port/demo/workflow/lists/demo_workflow
  3. 工作正常。

    现在我需要使用Java程序发送GET方法;下面是我的代码:


        HttpClient client = new HttpClient();
        HttpMethod method = new GetMethod("http://ec2-host:port/demo/workflow/lists/demo_workflow");
        HostConfiguration config = client.getHostConfiguration();
        config.setProxy(proxyHost, port);
        client.setHostConfiguration(config);
    
        try {
              client.executeMethod(method);
              if (method.getStatusCode() == HttpStatus.SC_OK) {
                 String response = method.getResponseBodyAsString();
                 System.out.println("Response = " + response);
              }
        } catch (IOException e) {
              e.printStackTrace();
        } finally {
              method.releaseConnection();
        }
    

    但是现在我遇到了以下例外情况。有什么提示吗?

      

    010-08-11 16:46:34,781 INFO   [HttpMethodDirector] I / O异常   (org.apache.commons.httpclient.NoHttpResponseException)   在处理请求时捕获:   服务器184.72.46.209无法响应   2010-08-11 16:46:34,781 INFO   [HttpMethodDirector]重试请求   org.apache.commons.httpclient.NoHttpResponseException:   服务器 [ec2-host] 失败   回应   org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1976)     在   org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1735)     在   org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1098)     在   org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)     在   org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)     在   org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)     在   org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)     at .... [我的代码抛出的地方   调用时的异常   client.executeMethod(配置)]

0 个答案:

没有答案