Good day, when developing android applications faced with a number of problems related to POST requests. Most of them I decided myself and with the help of this site. And when everything seemed to be done, another problem appeared, namely after I received a response from the server after a POST request. The answer looks like a digit from 0 to 23, then I can’t do anything except display it. I get a response from the server like this:
String bTime = EntityUtils.toString(response.getEntity(), "UTF-8");
or this method also works:
bTime = convertStreamToString(response.getEntity().getContent()); //...... public static String convertStreamToString(InputStream is) { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line = null; try { while ((line = reader.readLine()) != null) { sb.append(line);// + "\n"); } } catch (IOException e) { e.printStackTrace(); } finally { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } return sb.toString(); }
I tried to compare the received String with another String by the function .equals (str), but nothing happened, the comparison is always false, I tried to turn the String into an int by the function int BeginTime = Integer.parseInt (bTime.toString ()), Integer.parseInt (bTime) , int Time = Integer.valueOf (bTime.toString ()), Integer.valueOf (bTime), but when trying to convert a string to a number, the application threw out with an error.
Thus, I have a response from the server, but I can do nothing with it, except for the output to the screen. I ask you to tell what to do and how, in the end, I wanted to use this answer so that I could apply the comparison function to equality with another digit on it. Thank you in advance.
response.getEntity().getContentLength()
. set breakpoint in eclipse before converting, see what you have in bTime in the zero character. From php climbs garbage, apparently. - Yura Ivanov