Вопрос

I am in middle of an issue where I am getting a string "INSERTED SUCCESSFULLY" as the response from my httprequest, my aim was to match it with a local string (same as above) however when I try to match them they dont match hence does not enter into my condition.

UrlEncodedFormEntity entity = new UrlEncodedFormEntity(postParameters);
request.setEntity(entity);             
HttpResponse response= httpClient.execute(request);
bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer stringBuffer = new StringBuffer("");
String line = "";
String LineSeparator = System.getProperty("line.separator");
while ((line = bufferedReader.readLine()) != null) {
stringBuffer.append(line + LineSeparator); 
}
bufferedReader.close();
String q = "INSERTED SUCCESSFULLY";
StringBuffer got = new StringBuffer(q);
Log.d("Response", stringBuffer.toString());//MY logcat shows "INSERTED SUCCESSFULLY"
if(stringBuffer.equals(got))
   {
               // Does not enter here
       Log.d("xyz", "Getting Response" + stringBuffer.toString());
      //some TASK
   }

That does anything to do with encoding. N.B:- my php code just echo "INSERTED SUCCESSFULLY".

I tried doing the following code as well with no success

if(stringBuffer.toString().equals("INSERTED SUCCESSFULLY")
Это было полезно?

Решение

if(stringBuffer.toString().trim().equals("INSERTED SUCCESSFULLY")  

try with this may be there were some starting or ending space

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top