Hi Pat and Freddy,
Thanks for the reply. Actually we are using core java. We are not using servlets here and we are using HttpURLConnection itself. But no luck.
First of all is it possible to complete current requirement using Core java or we need to write Servlets for this?
Please find my requirement
1) Need to send a file to one of appliance.
2) Rather than appliance pulling file from machine, we have to push the file.
3) Appliance will accept only Http connections.
So, we are trying to push the file using HttpURLConnection. Please find the code which we are trying.
public class Demohttp
{
static URL url;
public static
String encode (String source)
{
BASE64Encoder enc = new sun.misc.BASE64Encoder();
return(enc.encode(source.getBytes()));
}
public static void main(String args[])
{
try
{
int x;
url = new URL("http://1.2.2.4");
HttpURLConnection con;
BufferedInputStream bufIn;
String user="admin";
String password="admin123";
String stringUserPassword = user + ":" + password;
String base64UserPassword = encode(stringUserPassword);
con = (HttpURLConnection)url.openConnection();
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestProperty("Connection", "Keep-Alive");
con.setRequestProperty("Authorization", "Basic "+base64UserPassword);
con.connect();
}
catch (Exception e)
{
System.out.println("in catch" +e);
}
}
}
The above code does the connectivity and once connection is done, we have to push file from our local location to appliance.
Please let me know ,for the current requirement, is the approach works or do we need to use anything else.
thanks,
Jags