我想从我的Android应用程序连接到django服务器.我正试图访问我的api,并POST提出请求.一切都准备好了.所有的参数和标题都需要,但我仍然得到这个错误.
log: [490] BasicNetwork.performRequest: Unexpected response code 401 for https://example.com/
Run Code Online (Sandbox Code Playgroud)
这不是让我访问我的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; …Run Code Online (Sandbox Code Playgroud)