G
Generic Usenet Account
I finally found the solution for this. As one poster pointed out, we
need to use HttpClient.java
Note that the following solution requires java 1.4
But you also need various other things. I have given them below:
a) HttpClient.java -- I used commons-httpclient-2.0.jar
b) commons-logging-api.jar
c) EasySSLProtocolSocketFactory.java
d) EasyX509TrustManager.java
a) and b) can be found here:
http://cvs.apache.org/builds/jakarta-commons/nightly/
c) and d) can be found here:
http://cvs.apache.org/viewcvs.cgi/j...ib/org/apache/commons/httpclient/contrib/ssl/
Here is a sample code that uses these to send https message to a
server.
Siva
----------- sample code begin -----------------
import javax.net.ssl.*;
import java.net.*;
import java.io.*;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.protocol.*;
import org.apache.commons.httpclient.methods.*;
public class HttpsTester{
private void process( String ip, String port, HttpClient
httpclient)
{
String line = /* get the line to send to server */
GetMethod get = new GetMethod("/" + line);
try{
httpclient.executeMethod(get);
}
catch (Exception e) {
System.out.println("unable to execute request: " + e);
return;
}
//output will be here
byte[] responseBody = get.getResponseBody();
//process the output
}
public static void main(String [] args)
{
String ip = args[1];
String port = args[2];
int portNum = 0;
try {
portNum = Integer.parseInt(port);
}
catch (Exception e)
{
System.out.println("invalid port number -- must be numeric");
return;
}
//get a protocol object and specify which SSL protocol we
// are going to use.
//https indicates that we want to use SSL connection
Protocol myhttps = new Protocol("https",
new EasySSLProtocolSocketFactory(), portNum);
HttpClient httpclient = new HttpClient();
//specify ip address, port number and the protol to use
httpclient.getHostConfiguration().setHost(ip, portNum, myhttps);
HttpsTester tester = new HttpsTester();
System.out.println("connecting at ip = " + ip +
" port = " + port);
//read from a file and execute each line
tester.process(ip, port, httpclient);
}
}
------------- sample code ends
need to use HttpClient.java
Note that the following solution requires java 1.4
But you also need various other things. I have given them below:
a) HttpClient.java -- I used commons-httpclient-2.0.jar
b) commons-logging-api.jar
c) EasySSLProtocolSocketFactory.java
d) EasyX509TrustManager.java
a) and b) can be found here:
http://cvs.apache.org/builds/jakarta-commons/nightly/
c) and d) can be found here:
http://cvs.apache.org/viewcvs.cgi/j...ib/org/apache/commons/httpclient/contrib/ssl/
Here is a sample code that uses these to send https message to a
server.
Siva
----------- sample code begin -----------------
import javax.net.ssl.*;
import java.net.*;
import java.io.*;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.protocol.*;
import org.apache.commons.httpclient.methods.*;
public class HttpsTester{
private void process( String ip, String port, HttpClient
httpclient)
{
String line = /* get the line to send to server */
GetMethod get = new GetMethod("/" + line);
try{
httpclient.executeMethod(get);
}
catch (Exception e) {
System.out.println("unable to execute request: " + e);
return;
}
//output will be here
byte[] responseBody = get.getResponseBody();
//process the output
}
public static void main(String [] args)
{
String ip = args[1];
String port = args[2];
int portNum = 0;
try {
portNum = Integer.parseInt(port);
}
catch (Exception e)
{
System.out.println("invalid port number -- must be numeric");
return;
}
//get a protocol object and specify which SSL protocol we
// are going to use.
//https indicates that we want to use SSL connection
Protocol myhttps = new Protocol("https",
new EasySSLProtocolSocketFactory(), portNum);
HttpClient httpclient = new HttpClient();
//specify ip address, port number and the protol to use
httpclient.getHostConfiguration().setHost(ip, portNum, myhttps);
HttpsTester tester = new HttpsTester();
System.out.println("connecting at ip = " + ip +
" port = " + port);
//read from a file and execute each line
tester.process(ip, port, httpclient);
}
}
------------- sample code ends