HTTPConnection with SSL
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   daniel_tejerina
Posted On:   Monday, April 7, 2003 04:23 AM

Hello, i've a problem to realice a HTTPConnection using a https protocol. When i use https protocol and i close the OutputStream i receive a nullpointerException, but if i use http protocol it works fine. what am i doing wrong? thanks public String conexion() throws Exception{ //String XMLResponse=null; String xmlResponse = ""; StringBufferInputStream is=null; DataInputStream resultStream=null; try{ //NVPair form_data[] = new NVPair[1]; //form_data[0] = new NVPair("XML", xml); //byte[] data=xml.getBytes(); System.out.println("8 headers"); NVPair headers[] = new NVPair[8]; headers[0]=new NVPair(&quo   More>>

Hello, i've a problem to realice a HTTPConnection using a https protocol.
When i use https protocol and i close the OutputStream i receive a nullpointerException, but if i use http protocol
it works fine.
what am i doing wrong?
thanks

public String conexion() throws Exception{
//String XMLResponse=null;

String xmlResponse = "";
StringBufferInputStream is=null;
DataInputStream resultStream=null;
try{
//NVPair form_data[] = new NVPair[1];
//form_data[0] = new NVPair("XML", xml);
//byte[] data=xml.getBytes();
System.out.println("8 headers");
NVPair headers[] = new NVPair[8];
headers[0]=new NVPair("accept","image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*");
headers[1]=new NVPair("accept-language", "es");
headers[2]=new NVPair("content-type",
"multipart/form-data; boundary=---------------------------7d21ef262004c");
headers[3]=new NVPair("accept-encoding", "gzip, deflate");
headers[4]=new NVPair("user-agent",
"Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)");
headers[5]=new NVPair("connection", "Keep-Alive");
headers[6]=new NVPair("cache-control", "no-cache");
headers[7]=new NVPair("content-length",String.valueOf(xml.getBytes().length));

System.getProperties().put("java.protocol.handler.pkgs", "HTTPClient");

HTTPConnection con = new HTTPConnection(url);
//System.out.println("URI::"+url.toString());
//uri=new URI(url.toString());
//HTTPConnection con = new HTTPConnection(uri);
con.setTimeout(time);

System.out.println("2::"+url.getFile()+"#");
HttpOutputStream outS=new HttpOutputStream();
HTTPResponse rsp = con.Post(url.getFile(),outS,headers);
System.out.println("3");
System.out.println("Long String XML:"+xml.length());
byte[] xmlB=xml.getBytes();
System.out.println("Long String XML bytes :"+xmlB.length);
outS.write(xmlB);
//is=new StringBufferInputStream(xml);
//System.out.println("Antes de copiar");
//copiar(is, outS);
//System.out.println("Despues de copiar");
System.out.println("Long OutPutStream"+outS.getLength());
System.out.println("Cadena OutPutStream"+outS.toString());

System.out.println("34433443");

//outS.close();
System.out.println("4");
InputStream IST=rsp.getInputStream();
System.out.println("5");
resultStream =new DataInputStream(IST);
String inputLine;
System.out.println("222222222");
while ((inputLine = resultStream.readLine()) != null) {
System.out.println(inputLine+"
");
xmlResponse += inputLine + "
";
}
System.out.println("fin del try");
}catch (Exception e){
System.out.println(" "+e);
} finally {
resultStream.close();
return xmlResponse;
}
}

private void copiar(InputStream is, HttpOutputStream os) throws IOException {
byte[] b = new byte[1024];
int leidos = b.length;
System.out.println("Antes WHILE"+leidos);
while (leidos == b.length) {
System.out.println("1111");
leidos = is.read(b);
System.out.println("leidos="+leidos);
os.write(b, 0, leidos);
System.out.println("2222");
}
System.out.println("Despues WHILE");
}

   <<Less
About | Sitemap | Contact