Note that there are some explanatory texts on larger screens.

plurals
  1. POIssues comparing the result of an HttResponse in android
    primarykey
    data
    text
    <p>I'm having an issue trying to compare the result of an HttpResponse with an simple string.</p> <p>What the code below do, is just get the response of an Http request. In this case the result of the request is a simple "ok", but when I try to compare it with another string the conditional doesn't work.</p> <p>I'm able to show the response via toast message...to debug it and to confirm that it is what I'm expecting, but I don't know why the conditional is not working.</p> <p>Thank's in advance.</p> <p><code> imports go here...</p> <p>public class HttpTest extends Activity {</p> <pre><code>public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); DownloadWebPageTask task = new DownloadWebPageTask(); task.execute(new String[] { "http://www.ecoeficiencia-ambiental.com/test/" }); } private class DownloadWebPageTask extends AsyncTask&lt;String, Void, String&gt; { protected String doInBackground(String... urls) { String response = ""; for (String url : urls) { DefaultHttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); try { HttpResponse execute = client.execute(httpGet); InputStream content = execute.getEntity().getContent(); BufferedReader buffer = new BufferedReader(new InputStreamReader(content)); String s = ""; while ((s = buffer.readLine()) != null) { response += s; } } catch (Exception e) { e.printStackTrace(); } } return response; } protected void onPostExecute(String result) { if(result == "ok"){ Toast.makeText(HttpTest.this, result, Toast.LENGTH_LONG).show(); }else{ Toast.makeText(HttpTest.this, "the conditional fails, the result is: "+result, Toast.LENGTH_LONG).show(); } } } </code></pre> <p>} </code></p> <p>Note: the manifest has the permission to use internet. both the code and the URL are functional.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload