I am having difficulty trying to get the body of the HTTP response from the string. So according to my code, I should have response from the PHP page in the string called "responseString" however because this is in an ASynchTask, I can not access that string anywhere else, so how can I receive the string?
For example, I would like to shoot this string into a text view for testing purposes, how can I do that? Am I reading the code incorrectly? Is the response I am getting not being put into that string?
Here is my code:
class RequestTask extends AsyncTask<String, String, String>{
@Override
protected String doInBackground(String... uri) {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response;
String responseString = null;
try {
response = httpclient.execute(new HttpGet(uri[0]));
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
out.close();
responseString = out.toString();
} else{
//Closes the connection.
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
} catch (ClientProtocolException e) {
//TODO Handle problems..
} catch (IOException e) {
//TODO Handle problems..
}
return responseString;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
}
}
I am using the following to execute:
new RequestTask().execute("http://www.mywebsite.com/android/registercheck.php?first=" + first2 + "&last=" + last2 + "&dispname=" + display2 + "&email=" + email2 + "&password=" + password2 );
onPostExecute
.t=(TextView)findViewById(R.id.resulttext); t.setText(responseString);
returns: The method findViewById(int) is undefined for the type RequestTask