File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java Micro Edition and the fly likes HttpConnection error only in devices (not emulators) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "HttpConnection error only in devices (not emulators)" Watch "HttpConnection error only in devices (not emulators)" New topic

HttpConnection error only in devices (not emulators)

Diego Guidi

Joined: Sep 09, 2004
Posts: 4
I've developed a client application in j2me and nokia emulators:
this app get mapi "text/text" (simple ASCII document) informations by a server and shows this informations on screen.
My problem is: in emulators (any nokia emulator (6600, 7210, S40), most siemens and sonyericsson) the app works fine, but in my devices (nokia 3200 and nokia 7250i) i receive a connection error 502 (HTTP_BAD_GATEWAY).

I've developed a test method: this method works on emulators but not in devices...

This is the code:

public void testHttpReturnString()
String url = "http://" + serverName + ":" + portNumber + "/projectlist." + getRandomInt() + "?user=" + getUserName() + "&pwd=" + getPassword();
byte[] buffer = null;
HttpConnection conn = null;
String response = "";
conn = (HttpConnection), Connector.READ);
int responseCode = conn.getResponseCode();
if(responseCode != HttpConnection.HTTP_OK)
System.out.println("Response error: code " + responseCode);
response = "Response error: code " + responseCode;// in devices return code 502, in emulators returns HTTP_OK
InputStream is = conn.openInputStream();
System.out.println("Type: " + conn.getType());// returns "text/text" in emulators (correct)
int size = (int)conn.getLength();
buffer = new byte[size];
int ch;
int i = 0;
while((ch = != -1)
buffer[i] = (byte)ch;
response = new String(buffer);
catch(IllegalArgumentException err)
response = "httpConnect IllegalArgumentException: " + err.toString();
catch(NullPointerException err)
response = "httpConnect NullPointerException: " + err.toString();
catch(IOException err)
response = "httpConnect IOException: " + err.toString();
DebugTextBox form = new DebugTextBox("Debug Form", response, this);// Debug form for retrieve informations from device

Any suggestions?

Thanks a lot
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Unfortunately, I don't have a suggestion for your code.

However, I have a suggestion for posting code.

We have a "CODE" tag, that can be created by clicking the CODE button, which is located under the "Add Reply" button, along with URL, BOLD, etc. buttons

This tag will enable you to keep your formatting for your code, like indentation, and makes your code readable. The way your code is posted makes it difficult to read, and therefore, more difficult for us to help you.



Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Ed Schepis

Joined: Feb 06, 2004
Posts: 25
Often on devices you need to configure a web profile instead of a wap one. In fact some telco operators permit the network connections only if a web profile is used. Are you testing your application in Italy? (... I guess it from your name...). Let me know if you need more information on profiles to use in italian devices.

SCMAD 1.0 - SCEA - SCJA - [<a href="" target="_blank" rel="nofollow">My Weblog</a>]
Diego Guidi

Joined: Sep 09, 2004
Posts: 4
Thanks for the information about <code> tag and thanks for replies...

I have locate the cause of the problem: i'ts a problem of configuration.

Vodafone and Wind mobile operators (italy) not allow to htp connections via wap configurations, but TIM operator allow this...

Result: program works crrectly with TIM operator, not with other operators.
Don't get me started about those stupid light bulbs.
subject: HttpConnection error only in devices (not emulators)
It's not a secret anymore!