4 Replies Latest reply: Apr 12, 2013 1:59 PM by 888525 RSS

    Connect to a url using httpclient

    888525
      I want to connect to a url using httpClient.
      Can someone help me with the steps or the code to do so?
      Also what jar files I need to have httpClient.

      Thanks,
        • 1. Re: Connect to a url using httpclient
          gimbal2
          Maybe spend more than 5 minutes looking at the website :/

          http://hc.apache.org/httpclient-3.x/

          I spot:

          a) a download link
          b) user guides
          c) sample code

          Yeah, I think everything you need is right there, no need to ask others to invest their time into doing that which you can -easily- do yourself.
          • 2. Re: Connect to a url using httpclient
            888525
            Thanks for the reply.I used the following code and geting the below error

            public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
            try
            {
            DefaultHttpClient http = new DefaultHttpClient();
            final String username = "domain\\username";
            final String password = "password";
            UsernamePasswordCredentials c = new UsernamePasswordCredentials(username, password);
            BasicCredentialsProvider cP = new BasicCredentialsProvider();
            cP.setCredentials(AuthScope.ANY, c);
            http.setCredentialsProvider(cP);
            String urlString = "http://mymachine/ReportServer/Pages/ReportViewer.aspx?";
            URL url = new URL(urlString);
            HttpPost post = new HttpPost(url.toURI());
            HttpResponse responseTest= http.execute(post);
            System.out.println(" The statusline is"+responseTest.getStatusLine());


            }
            catch(Exception ex)
            {
            System.out.println("The exception is"+ex);
            }
            }

            The error I am geting is


            Apr 12, 2013 10:45:00 AM org.apache.http.client.protocol.RequestAuthenticationBa
            se process
            WARNING: NEGOTIATE authentication error: Invalid name provided (Mechanism level:
            Could not load configuration file C:\Windows\krb5.ini (The system cannot find t
            he file specified))
            The statusline isHTTP/1.1 401 Unauthorized
            • 3. Re: Connect to a url using httpclient
              jtahlborn
              885522 wrote:
              The error I am geting is


              Apr 12, 2013 10:45:00 AM org.apache.http.client.protocol.RequestAuthenticationBa
              se process
              WARNING: NEGOTIATE authentication error: Invalid name provided (Mechanism level:
              Could not load configuration file C:\Windows\krb5.ini (The system cannot find t
              he file specified))
              The statusline isHTTP/1.1 401 Unauthorized
              I'm willing to bet google has a lot to say on this subject.
              • 4. Re: Connect to a url using httpclient
                888525
                I could solve this.I turned off WindowsNegotiate and it works now