
Originally Posted by
barbeNoire
Hi,
I have modified my code as follows but the problem remains the same. I can get data fine from the cgi script on the emulator but not from the real phone :
public String getMapFromMapServer2(String url) throws Exception {
StringBuffer b = new StringBuffer();
InputStream is = null;
OutputStream os;
HttpConnection c = null;
long len = 0;
int ch = 0;
c = (HttpConnection) Connector.open(url);
int rc = c.getResponseCode();
System.out.println("HTTP response code: " + rc);
if (rc != HttpConnection.HTTP_OK) {
throw new Exception("HTTP response code: " + rc);
}
is = c.openInputStream();
/*I need to hardcode the len value (size of returned image) because the cgi script does not fill the content-lenth header(len = c.getLength() returns null)*/
len = 200000;
System.out.println("Header content-length : " + c.getHeaderField("Content-length"));
if (len != -1) {
// Read exactly Content-Length bytes
for (int i = 0; i < len; i++)
//This is the issue : is.read() returns -1 !!!!
if ((ch = is.read()) != -1) {
b.append((char) ch);
}
}
return b.toString();
}
I get Http 200 response code from the server. However, the returned inputStream is null (-1).
Why does is.read() returns -1 on the mobile phone but not from the emulator?
What could be the problem?
Thanks