简体   繁体   English

Android Studio Volley库(基本网络错误)

[英]Android Studio Volley Library(BasicNetwork Error)

I Followed some tutorials for connecting phpMyAdmin(WAMP) to my android studio. 我按照一些教程将phpMyAdmin(WAMP)连接到我的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. 我正在使用我的Device(Lollipop 5.0)和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: 这是我的android代码:

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. 得出这样的结论是合乎逻辑的:由于CSRF保护,您的服务器正在创建403禁止响应。 You can confirm that this is indeed the case by looking at the webserver log file. 您可以通过查看Web服务器日志文件来确认确实如此。

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. 您有两种选择,如果您没有任何关键数据,请关闭该URL的CSRF保护,或者对相同的URL进行get请求,以便正确设置Cookie。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM