basic authentication with HTTP post request

Mahesh Venkat (mvenkat@marketfirst.com)
Wed, 18 Aug 1999 11:01:36 -0700

Date: Wed, 18 Aug 1999 11:01:36 -0700
From: Mahesh Venkat <mvenkat@marketfirst.com>
To: java-security@java.sun.com
Subject: basic authentication with HTTP post request

Hi,

I am using the following code (jdk1.1.8) to pass username and
password
to open connection to a url site . But I am unable to get a HTTP
inputstream handle.
The web site is managed by IIS 4.0 , where basic authentication
is turned on . As per IIS documentation, the username and password
corresponds
to the Windows NT ACL list .

URL url = new URL(m_nurlStr);
URLConnection urlconn = url.openConnection();

System.out.println(" POST " + url.getPort() + ": " + argStr + ",
URL is :" + url.toString());
urlconn.setAllowUserInteraction(false);
urlconn.setUseCaches(false);

String userPassStr = username + ":" + password;
byte[] upByte = userPassStr.getBytes();
urlconn.setRequestProperty("Authorization",
MyBase64.EncodeBase64PatchEx(upByte, 0 , upByte.length));

urlconn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");

System.out.println(" outputstream ...");
urlconn.setDoOutput(true);
urlconn.setDoInput(true);
//BufferedOutputStream out = new
BufferedOutputStream(urlconn.getOutputStream());
OutputStream out = urlconn.getOutputStream();
byte[] bOut = argStr.getBytes();
out.write( bOut, 0, bOut.length);
out.flush();
out.close(); // ESSENTIAL for this to work!
System.out.println(" outputstream closed ");

// POST the request data (html form encoded)
// Read the POST response data
url_inputstreamrdr = new
InputStreamReader(urlconn.getInputStream());
url_br = new BufferedReader(url_inputstreamrdr);
System.out.println(" bufferedinputstream obtained ");

Appreciate any clues with respect to this code or any other hint .

TIA
Mahesh