6
我試圖從我的android應用程序連接到django服務器。我試圖訪問我的api,使用volly發出POST
請求。一切都設定好了。所有的參數和頭文件都需要,但是我仍然得到這個錯誤。com.android.volly.AuthFailureError在向django服務器發出基本的volly POST請求
log: [490] BasicNetwork.performRequest: Unexpected response code 401 for https://example.com/
它不讓我訪問我的Django Api。它適用於PHP服務器。
public void vollyRequest()
{
RequestQueue queue = Volley.newRequestQueue(this);
StringRequest request = new StringRequest(Request.Method.POST , "https://example.com/", new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(MainActivity.this, "RESPONSE: " + response, Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, "ERROR: " + error, Toast.LENGTH_SHORT).show();
}
}) {
@Override
protected Map<String,String> getParams(){
Map<String,String> params = new HashMap<String, String>();
params.put("username","***");
params.put("password","***");
return params;
}
// @Override
// public Map<String, String> getHeaders() throws AuthFailureError {
// Map<String,String> params = new HashMap<String, String>();
// params.put("Content-Type","application/x-www-form-urlencoded");
// return params;
// }
};
queue.add(request);
}
我與Php服務器有同樣的錯誤 –
@CodeWarrior你解決了這個問題嗎? –