I am using this adt code to fetch echo data from php url.
class asynctask 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);
responseString = out.toString();
out.close();
} else{
//Closes the connection.
response.getEntity().getContent().close();
}
} catch (ClientProtocolException e) {
//TODO Handle problems..
} catch (IOException e) {
//TODO Handle problems..
}
return responseString;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
///////////////////////////////////////////////
Toast.makeText(getApplicationContext(), result, Toast.LENGTH_LONG).show();
try {
// txv1.setText(result);
}
catch (Exception e) {
// TODO: handle exception
}
}
}
And Call from -
new asynctask().execute("http://mmbics.com/get.php");
It is really not working even I see what is echoing on php url. It can show other php echo without mysql request. Please kindly help me. It can't show this php echo too.
http://mmbics.com/index.php
First I would suggest that the DefaultHttpClient is deprecated. You should change it to the OkHttp Client or HttpUrlConnect. See below code snippet that you can take as a reference for make this get request.
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("http://mmbics.com/get.php")
.get()
.build();
Response response = client.newCall(request).execute();
Let me know if you stuck with it.It's simple Http Get Request call.
Thanks.
Use Volley its network connectoin lib, its easy and powerfull lib so its better to call your url by this,
StringRequest strReq = new StringRequest(Method.GET,
Const.URL_STRING_REQ, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, response.toString());
msgResponse.setText(response.toString());
hideProgressDialog();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
hideProgressDialog();
}
}) {
@Override
public Priority getPriority() {
return priority;
}
};
check this reference: http://www.androidhive.info/2014/05/android-working-with-volley-library-1/