The forum has changed a lot since I last posted something. I don't know where to post my little problem I'm having with the J2ME HTTP GET Request so I'll post it here. I have a code similar to the one above.It works fine on the WTK emulator, it works fine on Nokia 6230 and 6230i, but it doesn't work on Nokia 6630. I've "heard" there is an issue regarding Nokia 6630 when it comes to HTTP Get request in J2ME but I don't exactly know what that issue is. The problem actually is that I don't receive anything from my server not even a "Hello World" text. It looks like the DataInputStream.read() method returns for some unknown reason -1. But on Nokia 6230 it works perfectly and in the WTK of course. The server side code is a simple php code. My J2ME client code is:
HttpConnection hcon = null;
DataInputStream dis = null;
StringBuffer response = new StringBuffer();
try {
hcon = (HttpConnection) Connector.open(requestUrl);
hcon.setRequestMethod(HttpConnection.GET);
hcon.setRequestProperty("User-Agent","Profile/MIDP-2.0 Confirguration/CLDC-1.0");
hcon.setRequestProperty("Content-Language", "en-CA");
hcon.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
dis = new DataInputStream(hcon.openInputStream());
System.out.println("connecting to: " + requestUrl);
int ch;
while ((ch = dis.read()) != -1) {
response.append((char) ch);
}
} catch (Exception ex) {
throw ex;
} finally {
if (dis != null) {
dis.close();
dis = null;
}
if (hcon != null) {
hcon.close();
hcon = null;
}
}
Hey, you should ask the question in the Forum Nokia discussion boards. It is kind of hidden in the Wiki...
http://discussion.forum.nokia.com
Review:
This article contains a useful code example on how to use HTTP GET requests in Java ME. HTTP GET requests allow us to download data via HTTP. In Java ME, the default HTTP method when an HttpConnection is opened is GET. The article provides a full midlet (although a short one) demonstrating the use of the HttpConnection object. A connection is opened and data is read one character at a time via a DataInputStream.
This article shows the correct use of the HttpConnection for retrieving data using HTTP. One thing missing from the code is that often we can retrieve the length of the data to be downloaded via HTTP, which can enable more efficient downloading, as we can download chunks at a time, rather than a character at a time. Generally, the code example is well written. Good use is made of comments to explain the content. The exception handling demonstrated is also good.
--Larry101 21:57, 29 September 2009 (UTC)
This article demonstrates a new way to make a HTTP GET request. The Code represented, in this article, can be considered a short module of Web browser. In this article, It has a form; it appends a text field, and sets two commands SEND and BACK. When you write any website address and click on SEND, GET request is sent to server and retrieve a string from server. That is used to display the page content retrieved from server. So the web page is displayed and if you click on a BACK button then the main form is retrieved.
I can easily understand this code snippet. Because this code is easily represented. So like me, every body can easily gain knowledge from this article.
--Vkmunjpara 20:09, 30 September 2009 (UTC)