Hello,
I am stuck with the same problem for a couple of days - I did a fair amount of reading on this forums and others, but it seems I just can't solve it.
I am trying to get a web page (text) from a web server with my 6230i. I works with the emulator, but when I run it on the device, I get a IOException error : Error in HTTP Operation.
What I did (and didn't change a thing) :
- start the connection in a different thread
- change POST to GET
- add and remove various headers
- add sleep time at various locations
And of course I can connect and view the page using the embedded web browser. Apparently the access point is the provider's WAP gateway.
Please help, I'm running out of ideas.
Thanks,
Alex
//code :
DataInputStream dis = null;
DataOutputStream dos = null;
StringBuffer responseMessage = new StringBuffer();
String response = null;
HttpConnection hcon = null;
try {
hcon = ( HttpConnection )Connector.open( testUrl, Connector.READ_WRITE );
hcon.setRequestMethod( HttpConnection.GET );
if (hcon.getResponseCode() == HttpConnection.HTTP_OK) {
dis = hcon.openDataInputStream();
// Get the length and process the data
int len = (int) hcon.getLength();
if (len > 0) {
byte[] chars = new byte[len];
int actual = dis.read(chars);
response = new String(chars);
//process(data);
} else {
int ch;
while ((ch = dis.read()) != -1) {
responseMessage.append( (char)ch );
}
if (responseMessage.length() > 0) {
response = responseMessage.toString();
}
}
}
}
catch( IOException e ) {
write(e.toString());
}
finally {
// free up i/o streams and http connection
try {
if( hcon != null ) hcon.close();
if( dis != null ) dis.close();
if( dos != null ) dos.close();
} catch ( IOException ioe ) {
ioe.printStackTrace();
}//end try/catch
}//end try/catch/finally

Reply With Quote

