Hi,
I installed Opera and managed to surf through WAP APN.
Here is the code I am using to establish the connection:
Code:
private void readContents(String request)
{
StringBuffer b = new StringBuffer();
attempt++;
b.append("attempt " + attempt + " content of " + request + " " + url + "\n");
HttpConnection c = null;
OutputStream os = null;
InputStream is = null;
TextBox t = null;
try
{
long len = -1L;
int ch = 0;
long count = 0L;
DEBUG(request + " Page: " + url);
c = (HttpConnection)Connector.open(url);
DEBUG("c= " + c);
c.setRequestMethod(request);
c.setRequestProperty("foldedField", "first line\r\n second line\r\n third line");
if(request == "POST")
{
String m = "Test POST text.";
DEBUG("Posting: " + m);
os = c.openOutputStream();
os.write(m.getBytes());
os.close();
os.flush();
java.io.DataInputStream datainputstream = c.openDataInputStream();
}
int rc = c.getResponseCode();
if(rc != 200)
{
b.append("Response Code: " + c.getResponseCode() + "\n");
b.append("Response Message: " + c.getResponseMessage() + "\n\n");
}
is = c.openInputStream();
DEBUG("is = " + is);
if(c instanceof HttpConnection)
len = c.getLength();
DEBUG("len = " + len);
if(len != -1L)
{
DEBUG("Content-Length: " + len);
for(int i = 0; (long)i < len; i++)
{
if((ch = is.read()) == -1)
continue;
if(ch <= 32)
ch = 32;
b.append((char)ch);
count++;
if(count > 200L)
break;
}
} else
{
byte data[] = new byte[100];
int n = is.read(data, 0, data.length);
for(int i = 0; i < n; i++)
{
ch = data[i] & 0xff;
b.append((char)ch);
}
}
try
{
if(is != null)
is.close();
if(c != null)
c.close();
}
catch(Exception ce)
{
DEBUG("Error closing connection");
}
try
{
len = is.available();
DEBUG("Inputstream failed to throw IOException after close");
}
catch(IOException io)
{
DEBUG("expected IOException (available())");
io.printStackTrace();
}
t = new TextBox("Http Test", b.toString(), b.length(), 0);
is = null;
c = null;
}
catch(IOException ex)
{
ex.printStackTrace();
DEBUG(ex.getClass().toString());
DEBUG(ex.toString());
DEBUG("Exception reading from http");
if(c != null)
{
try
{
String s = null;
if(c instanceof HttpConnection)
s = c.getResponseMessage();
DEBUG(s);
if(s == null)
s = "No Response message";
t = new TextBox("Http Error", s, s.length(), 0);
}
catch(IOException e)
{
e.printStackTrace();
String s = e.toString();
DEBUG(s);
if(s == null)
s = ex.getClass().getName();
t = new TextBox("Http Error", s, s.length(), 0);
}
try
{
c.close();
}
catch(IOException ioexception) { }
} else
{
t = new TextBox("Http Error", "Could not open URL", 128, 0);
}
}
catch(IllegalArgumentException ille)
{
t = new TextBox("Illegal Argument", ille.getMessage(), 128, 0);
}
catch(Exception e)
{
t = new TextBox("Error", e.toString(), 128, 0);
}
if(is != null)
try
{
is.close();
}
catch(Exception exception) { }
if(c != null)
try
{
c.close();
}
catch(Exception exception1) { }
setCommands(t, false);
display.setCurrent(t);
}
Thanks,
Kobi Toueg