I am getting errorResponse instead of the normal response i should have got. I have made a simple php file with a simple text and put it on the wamp server. And i have checked it on the browser it works fine but not in this code.
public class MainActivity extends AppCompatActivity {
Button button;
TextView textView;
String server_url="http://192.168.1.2/greetings.php";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button= (Button) findViewById(R.id.bn);
textView= (TextView) findViewById(R.id.txt);
final RequestQueue requestQueue= Volley.newRequestQueue(MainActivity.this);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
StringRequest stringRequest=new StringRequest(Request.Method.POST, server_url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
textView.setText(response);
requestQueue.stop();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
textView.setText("something wrong happened");
error.printStackTrace();
requestQueue.stop();
}
});
requestQueue.add(stringRequest);
}
});
}
}