org.apache.commons.httpclient.demo.BasicAuthenticationDemo.java Source code

Java tutorial

Introduction

Here is the source code for org.apache.commons.httpclient.demo.BasicAuthenticationDemo.java

Source

package org.apache.commons.httpclient.demo;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.methods.GetMethod;

/*
 7 
    
 HTTPhttpclientNTLMHTTP 1.1NTLMNTLM
    
*/

public class BasicAuthenticationDemo {

    public BasicAuthenticationDemo() {

    }

    @SuppressWarnings("deprecation")
    public static void main(String[] args) throws Exception {

        HttpClient client = new HttpClient();
        //
        //client.getHostConfiguration().setProxy("90.0.12.21",808);

        client.getState().setCredentials("www.verisign.com", "realm",
                new UsernamePasswordCredentials("username", "password"));

        GetMethod get = new GetMethod("https://www.verisign.com/products/index.html");
        get.setDoAuthentication(true);

        int status = client.executeMethod(get);
        System.out.println(status + "" + get.getResponseBodyAsString());
        get.releaseConnection();
    }
}