0

I am trying to invoke a web service from an Eclipse program. But I am getting response code 500 as response. When I access the URL from IE or Mozilla it works fine for me. My sample Eclipse program:

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();
   }
}

When I opened the link in IE or Mozilla I am getting exact output. The credentials are correct.

Can any one help to overcome this.

Thanks.

4

0 回答 0