I Followed some tutorials for connecting phpMyAdmin(WAMP) to my android studio. I Followed the tutorial well and still getting this error.
what am i doing wrong? I'm using my Device(Lollipop 5.0) and Android Studio 1.0.
10-07 00:27:03.719 25314-25616/com.example.galvez.php E/Volley﹕ [11353] BasicNetwork.performRequest: Unexpected response code 403 for http://192.16*.**.**/poi/showData.php
Heres my android code:
public class MainActivity extends Activity {
EditText POI,POILongLat,POIType,POIAddress,POIZipCode;
Button insertVal,showVal;
TextView textResult;
RequestQueue requestQueue;
String insertUrl="http://192.168.**.**/poi/insertData.php";
String showUrl="http://192.168.**.**/poi/showData.php";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
POI = (EditText) findViewById(R.id.txtPOI);
POILongLat=(EditText) findViewById(R.id.txtPOILongLat);
POIType = (EditText) findViewById(R.id.txtPOIType);
POIAddress = (EditText) findViewById(R.id.txtPOIAddress);
POIZipCode = (EditText) findViewById(R.id.txtPOIZipCode);
insertVal = (Button) findViewById(R.id.btnInsert);
showVal = (Button) findViewById(R.id.btnView);
textResult = (TextView) findViewById(R.id.txtResult);
requestQueue = Volley.newRequestQueue(getApplicationContext());
showVal.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view){
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST,
showUrl,new Response.Listener<JSONObject>(){
@Override
public void onResponse(JSONObject response) {
try {
JSONArray pois = response.getJSONArray("stud");
for(int i=0;i<pois.length();i++){
JSONObject pointOfInterest = pois.getJSONObject(i);
String strPOI = pointOfInterest.getString("POI");
String strPOILongLat = pointOfInterest.getString("POILongLat");
String strPOIType = pointOfInterest.getString("POILongLat");
String strPOIAddress = pointOfInterest.getString("POIAddress");
String strPOIZipCode = pointOfInterest.getString("POIZipCode");
textResult.append(strPOI+" "+strPOILongLat+" "+strPOIType+" "+strPOIAddress+" "+strPOIZipCode);
Log.v("",strPOI+" "+strPOILongLat+" "+strPOIType+" "+strPOIAddress+" "+strPOIZipCode);
}
textResult.append("===\n");
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
requestQueue.add(jsonObjectRequest);
}
});
}
If you look at the error message:
Unexpected response code 403
and how you make the request:
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST,
showUrl,new Response.Listener<JSONObject>()
It's logical to jump to the conclusion that your server is creating a 403 forbidden response due to CSRF protection. You can confirm that this is indeed the case by looking at the webserver log file.
You have two choices, switch off CSRF protection for that url if you do not have any critical data or make a get request to the same url so that cookies are set properly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.