Postman 的回复显示 200,但是 Android returns 403

Response from Postman shows 200, But Android returns 403

我正在尝试使用 Volley 开发一个 android 应用程序,当我检查 POSTMAN 并检索 200 时,我用来通信的 api 工作正常。

但是当我在我的应用程序中使用相同的 API 时,它 returns 我 403 "Forbidden" <p〉You don't have permission to access /API/checkPassOtp on this server.〈/p〉

请找截图。

针对这个问题我已经尝试了多种解决方案,但没有任何效果。

谁能帮帮我。

附加凌空码和错误响应

JSONObject jsonBody = new JSONObject();
try {
    jsonBody.put("otp", otp);
    Log.e("jsonBody", jsonBody.toString());
} catch (JSONException e) {
    e.printStackTrace();
}

JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST, URL, jsonBody, new Response.Listener<JSONObject>() {
    @Override
    public void onResponse(JSONObject response) {
        // handle response data
        VolleyHelper.progressDialog.dismiss();
        Log.e("onResponse", response.toString());

    }
}, new Response.ErrorListener() {

    @Override
    public void onErrorResponse(VolleyError error) {
        VolleyHelper.progressDialog.dismiss();
        Toast.makeText(getApplicationContext(),error.toString(),Toast.LENGTH_SHORT).show();
        Log.e("onErrorResponse", error.toString());

    }

}) {
    @Override
    public Map<String, String> getHeaders() throws AuthFailureError {
        Map<String, String> params = new HashMap<String, String>();
        params.put("Content-Type", "application/json");
        return params;
    }
};


jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 2, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
Application.getInstance().addToRequestQueue(jsonObjReq, "app");
volleyHelper.showProgressDialogWithTitle(MainActivity.this);

尝试使用

"Accept", "application/json"

在你的参数中(两者都用)。

我在连接我公司的网络服务器时必须使用 x-api-key,但我不确定您是否需要它。

--> 在 android 中使用 https 而不是 http ,Postman 似乎可以使用 http,但 OkHttp 需要 https。

我在 android 中因为这个错误 403 forbidden 被困了一天,但在 Postman 中给出了 200 成功。