通过eclipse访问基于休息的Web服务时的响应代码500

时间:2013-01-15 07:46:58

标签: java web-services rest

我正在尝试从Eclipse程序调用Web服务。但我得到响应代码500作为回应。当我从IE或Mozilla访问URL时,它对我来说很好。我的示例Eclipse程序:

public static void main(String[] args) {
   // Use apache commons-httpclient to create the request/response
   HttpClient client = new HttpClient();
   Credentials defaultcreds = new UsernamePasswordCredentials("aaa", "aaaa");
   client.getState().setCredentials(AuthScope.ANY, defaultcreds);

   GetMethod method = new GetMethod("http://localhost:8080/usersByID/2039");
   try {
      client.executeMethod(method);
      InputStream in = method.getResponseBodyAsStream();
      // Use dom4j to parse the response and print nicely to the output stream
      BufferedReader reader = new BufferedReader(new InputStreamReader(in));
      StringBuilder out = new StringBuilder();
      String line;
      while ((line = reader.readLine()) != null) {
         out.append(line);
      }
      System.out.println(out.toString());
   } catch (IOException e) {
      e.printStackTrace();
   }
}

当我在IE或Mozilla中打开链接时,我得到了准确的输出。凭证是正确的。

任何人都可以帮助克服这一点。

感谢。

0 个答案:

没有答案