相关疑难解决方法(0)

Android Volley - BasicNetwork.performRequest:意外的响应代码400

问题陈述:

我试图访问一个REST API,它将使用Volley返回各种HTTP状态代码(400,403,200等)的JSON对象.

对于200以外的任何HTTP状态,似乎"意外响应代码400"是一个问题.有没有人有办法绕过这个'错误'?

码:

protected void getLogin() {   
    final String mURL = "https://somesite.com/api/login";

    EditText username = (EditText) findViewById(R.id.username);
    EditText password = (EditText) findViewById(R.id.password);

    // Post params to be sent to the server
    HashMap<String, String> params = new HashMap<String, String>();
    params.put("username", username.getText().toString());
    params.put("password", password.getText().toString());

    JsonObjectRequest req = new JsonObjectRequest(mURL, new JSONObject(
            params), new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {

            try {
                JSONObject obj = response
                        .getJSONObject("some_json_obj");

                Log.w("myApp",
                        "status code..." + obj.getString("name"));

                // VolleyLog.v("Response:%n %s", response.toString(4));

            } catch (JSONException …
Run Code Online (Sandbox Code Playgroud)

android android-volley

22
推荐指数
4
解决办法
9万
查看次数

标签 统计

android ×1

android-volley ×1