(Java) HTTP Basic Authentication Test
Demonstrates how to do HTTP basic authentication using Chilkat.
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttp http = new CkHttp();
http.put_BasicAuth(true);
http.put_Login("foo");
http.put_Password("bar");
// Let's say we want to download a file that is protected by HTTP Basic Authenication..
boolean success = http.Download("https://www.example.com/someDir/document.pdf","qa_output/document.pdf");
if (success == false) {
System.out.println(http.lastErrorText());
return;
}
System.out.println("Success.");
}
}
|