why doenst this code work? in order to get a response from the server in android
try { 开发者_如何学C
HttpResponse response = new DefaultHttpClient().execute(
new HttpGet(requestString));
InputStream is = response.getEntity().getContent();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
while ((line=br.readLine()) != null){
long temp = Long.parseLong(line);
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Also check for valid response. Why would anyone cast web response to Long ?
Use StringBuilder or simple String for fetching response.
eg.
.
.
StringBuilder reponseBuilder=new StringBuilder("");
while ((line=br.readLine()) != null){
//long temp = Long.parseLong(line);
reponseBuilder.append(line);
}
.
.
And then use it as per scenario may be converting it to a String using:
reponseBuilder.toString();
and if still your facing same issue then, Yup, This is truly regarding invalid permission stuff.
Add below code,
<uses-permission android:name="android.permission.INTERNET">
as child of your manifest file. And this will work as magic.
You haven't told us what error you are getting, but my guess would be that this line is giving you problems:
long temp = Long.parseLong(line)
Are you trying to parse HTTP reply as series of lines where each line contains a long?
精彩评论