This is the code I am using... is there any mistake in this ?
I am getting an open tunnel failure while executing the code:
c = (HttpConnection)Connector.open(url);
Code:
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.io.HttpConnection;
import java.util.Vector;
import java.util.Enumeration;
import javax.microedition.io.Connector;
import net.rim.device.api.io.file.ExtendedFileConnection;
public class ReadHttpFile extends Thread{
HttpConnection c = null;
InputStream is = null;
String XMLdata = "";
int rc;
public boolean isInvalidFile=false;
String url;
ReadHttpFile(String URL) {
url = URL;
}
public void run() {
try{
ReadData(url);
}catch(IOException ie){
}
}
public void ReadData(String url) throws IOException{
try {
c = (HttpConnection)Connector.open(url);
// Getting the response code will open the connection,
// send the request, and read the HTTP response headers.
// The headers are stored until requested.
if(c!=null){
rc = c.getResponseCode();
if (rc != HttpConnection.HTTP_OK) {
isInvalidFile=true;
}
is = c.openInputStream();
StringBuffer sb = new StringBuffer();
int ch;
while ((ch = is.read()) != -1) {
sb.append((char) ch);
}
XMLdata = sb.toString();
System.out.println("XML "+ XMLdata);
}
}catch(IOException ioe){
System.out.println("Exception : "+ ioe.toString());
isInvalidFile=true;
}catch(Exception e){
System.out.println("Exception : "+ e.toString());
isInvalidFile=true;
} finally {
if (is != null)
is.close();
if (c != null)
c.close();
}
}
}