hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: client Authentification when using HttpMethod
Date Mon, 22 Nov 2004 22:45:43 GMT
Ryan,

First of all, what kind of authentication does the server
support/require?

HttpClient supports Basic/Disgest/NTLM authentication schemes as well as
form-based authentication.

For details on Basic/Disgest/NTLM authentication schemes see the
HttpClient authentication guide:

http://jakarta.apache.org/commons/httpclient/authentication.html

Form-based authentication is basically nothing more than a POST request
containing authentication credentials. 

Sample code can be found here:

http://cvs.apache.org/viewcvs.cgi/jakarta-
commons/httpclient/src/examples/FormLoginDemo.java?
rev=1.1.2.1&only_with_tag=HTTPCLIENT_2_0_BRANCH&view=markup

Hope this helps

Oleg

On Sun, 2004-11-21 at 05:48 +0100, Ryan julius wrote:
> Hi,
>  
> I would like to send a message (let say "templateFileString") to a remote server.  The
remote server requires the sender being authenticated. 
>  
> My Question :
> How can I use HttpMethod/HttpPost/... to send my message with my userName and Password
to the remote server.
>  
> The tutorial presented here does not mention the authentications:
>  
> 
> import org.apache.commons.httpclient.*;import org.apache.commons.httpclient.methods.*;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    DefaultMethodRetryHandler retryhandler
= new DefaultMethodRetryHandler();    retryhandler.setRequestSentRetryEnabled(false);    retryhandler.setRetryCount(3);
   method.setMethodRetryHandler(retryhandler);    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.      // U
 se
>  caution: ensure correct character encoding and is not binary data      System.out.println(new
String(responseBody));    } catch (IOException e) {      System.err.println("Failed to download
file.");      e.printStackTrace();    } finally {      // Release the connection.      method.releaseConnection();
   }  }}
> 
> How could I adapt it?
> 
>  
> 
> Thanks in advance.
> 
> 
> 		
> ---------------------------------
> Créez gratuitement votre Yahoo! Mail avec 100 Mo de stockage !
> Créez votre Yahoo! Mail
> 
> Le nouveau Yahoo! Messenger est arrivé ! Découvrez toutes les nouveautés pour dialoguer
instantanément avec vos amis.Téléchargez GRATUITEMENT ici !


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Mime
View raw message