I`ve developed a midlet to submit a score to a server and get back a response- ok, failed etc.
Below is the loop which connects to the url. It all runs fine on Nokias but throws a IOException when run
on Sony Ericsson (K700i) and Motorola (V3,V525,V500).
It seems to be thrown when the in = hc.openDataInputStream(); call is made.
When i attempt to connect, i get the screen asking whether i should allow the connection and then it fails.
Can anyone help??
I am unsure as to which hc.setRequestProperty to set. Could this be effecting it?
The url is a WAP page.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| public void run() { while(running) { HttpConnection hc = null InputStream in = null; OutputStream out = null; StringBuffer b= new StringBuffer(); try { hc = (HttpConnection)Connector.open(url); hc.setRequestMethod(HttpConnection.GET);
out = hc.openOutputStream(); in = hc.openDataInputStream(); int ch; System.out.println(" Responed= " ); while((ch=in.read()) != -1){ b.append((char)ch); System.out.println((char)ch); } doSomething(b); }
catch (ConnectionNotFoundException cnfe){System.out.println(cnfe);} catch (IOException ie){ System.out.println(ie);} finally { running=false; try { if(in!=null) in.close(); if(hc!=null) hc.close(); if(out!=null) out.close(); } catch(IOException ie){System.out.println(ie);} } } } |