Hello,
I am having problem downloading a text file vile htto connection.
I am the source code below to downloand the file and it is working well in any emulator and on the motorola razor phone.
But when i tried testing them on a nokia 3220 phone(ser 40), is throwingthis exception:
java.io.ioException: error in http operation
it is throwing exception on this line
is = c.openInputStream();
when i tried adding a get response code
int rc = c.getResponseCode();
it throws the exception in this line
Below is my source code:
/*********************source code***************** */
public String getDataFromUrl(String url) //throws IOException
{
int rc=0;
try{
StringBuffer b = new StringBuffer();
InputStream is = null;
HttpConnection c = null;
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.
is = c.openInputStream();
// Get the ContentType
String type = c.getType();
// Get the length and process the data
int len = (int)c.getLength();
if (len > 0) {
byte[] raw = new byte[len];
int length = is.read(raw);
b = new StringBuffer(new String(raw,0,length));
}else {
int ch;
while ((ch = is.read()) != -1)
{
len = is.available() ;
b.append((char)ch);
}
}
is.close();
return b.toString();
}catch(Exception e){
return null;
}
}

Reply With Quote


