2015-10-06 65 views
1

我遵循一些教程連接phpMyAdmin(WAMP)到我的android工作室。我很好地跟隨了教程,仍然得到這個錯誤。
我做錯了什麼?我正在使用我的設備(Lollipop 5.0)和Android Studio 1.0。Android Studio排球庫(BasicNetwork錯誤)

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 

繼承人我的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); 

     } 
    }); 
} 

回答

1

如果你看一下錯誤信息:

Unexpected response code 403 

選擇以及如何請求:

JsonObjectRequest jsonObjectRequest = new  JsonObjectRequest(Request.Method.POST, 
       showUrl,new Response.Listener<JSONObject>() 

它的邏輯跳到你的結論由於CSRF保護,服務器正在創建403禁止響應。您可以通過查看Web服務器日誌文件來確認確實如此。

您有兩種選擇,如果您沒有任何關鍵數據或對相同的URL發出獲取請求以便cookie正確設置,請關閉該URL的CSRF保護。

+0

感謝您的快速響應。我如何關閉CSRF?謝謝! –

+0

在PHP中沒有內置的CSRF支持,您的CSRF保護來自您的框架,因此您必須參考它。這當然假設日誌文件證實了我對CSRF導致403錯誤的預測。 – e4c5

+0

我真的不知道該怎麼做。我試過配置我的WAMP,但仍然沒有發生。 :'( –