Hi Casper,
I have tried your code using Nokia SDK 1.0 for Java. This is what I tried:
Code:
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class Temp2 extends MIDlet {
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {}
protected void pauseApp() {}
protected void startApp() throws MIDletStateChangeException
{
byte[] result;
try {
result=loadHttpFile("http://maps.google.com/maps/geo?q=beijing&output=csv&key=ABQIAAAA1VYVV9bbajQVMm7FPXPOpRS2trCutCFyfgUBYaUaRBDPahEgTRRx21RsVciHAjRSnyqMYb5VpxtCJA");
System.out.println(new String(result));
} catch (IOException e) {
System.out.println("Exception!");
}
}
private static byte[] loadHttpFile(String url) throws IOException
{
byte[] byteBuffer;
HttpConnection hc = (HttpConnection) Connector.open(url);
System.out.println("loadHttpFile:" + url);
try
{
hc.setRequestMethod(HttpConnection.GET);
InputStream is = hc.openInputStream();
try
{
int len = (int) hc.getLength();
if (len > 0)
{
byteBuffer = new byte[len];
int done = 0;
while (done < len)
{
done += is.read(byteBuffer, done, len - done);
}
}
else
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buffer = new byte[512];
int count;
while ((count = is.read(buffer)) >= 0)
{
bos.write(buffer, 0, count);
}
byteBuffer = bos.toByteArray();
}
}
finally
{
is.close();
}
}
finally
{
hc.close();
}
return byteBuffer;
}
}
And this is the result I got from the console:
200,4,39.9042140,116.4074130
In my case, no exception was thrown and everything worked as expected. In some cases, like when working from within a network that uses proxies to connect to the outside world, you would need to specify a proxy server so that the Emulator can connect to the web. If that's the case, you could ask your system administrator to provide the proxy server settings and then in the Emulator open Tools>Preferences>Networking> enter the proxy settings under HTTP Proxy Server.