喜的朋友我是新黑莓編程,我得到的問題,同時使HttpConnection的發送GET請求到PHP的Web服務,下面是我想的代碼,黑莓編程和Java ME
HttpConnection conn = null;
InputStream in = null;
StringBuffer buff = new StringBuffer();
String result = null;
String url = "http://localhost/blackberry/locations.php?device_id="+id+"&lat="+lat+"&lon="+lon
try{
conn = (HttpConnection) Connector.open(url,Connector.READ_WRITE, true);
conn.setRequestMethod(HttpConnection.GET);
conn.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Confirguration/CLDC-1.0");
if(conn.getResponseCode() == HttpConnection.HTTP_OK){
in = conn.openInputStream();
int chr;
//xp.parse(in, handler);
while((chr = in.read()) != -1){
buff.append((char)chr);
}
result = buff.toString();
}
else{
result = "Error in connection";
return result;
}
} catch(Exception ex){
System.out.println(ex.getMessage());
} finally{
try {
in.close();
conn.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
請建議我解決方案, 謝謝
注意。
請問具體問題是什麼? – razlebe 2011-06-16 10:40:58
你的問題是什麼?有什麼異常? – bharath 2011-06-16 10:44:26
我在上面的代碼中得到了nullPointerException。 – 2011-06-16 10:51:16