You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Volley请求返回403错误与AuthFailureError问题求助

Fixing Volley's 403 AuthFailureError When Accessing Local PHP Interface

Hey there, let's work through your Volley 403 AuthFailureError issue. You've already adjusted the require local setting in httpd-vhosts.conf, but the error persists—here are several targeted fixes to try:

1. Verify Apache's Directory-Level Permissions

Changing httpd-vhosts.conf might not be enough if your main httpd.conf file still has restrictive rules for the directory holding test.php. Open httpd.conf and locate the <Directory> block corresponding to your PHP file's folder, then update it to:

<Directory "/path/to/your/test.php/directory">
    AllowOverride All
    Require all granted
</Directory>

Don't forget to restart your Apache server after saving changes.

2. Check for Firewall or Security Blockages

  • Local Firewall: Ensure your server's firewall (Windows Firewall, Linux iptables, etc.) allows incoming traffic on port 80. Test connectivity by pinging 192.168.43.83 from your device/simulator, or using telnet 192.168.43.83 80 to confirm the port is open.
  • Apache Mod_Security: This module might flag your Volley request as malicious. Temporarily disable Mod_Security in Apache's config to see if the error goes away, or add a rule to whitelist your request.

3. Add a User-Agent Header to Your Volley Request

Some servers reject requests without a valid User-Agent, which can trigger a 403 error. Modify your JsonArrayRequest to include this header by overriding getHeaders():

Request request = new JsonArrayRequest(
    Request.Method.GET,
    "http://192.168.43.83/test.php",
    null,
    new Response.Listener<JSONArray>() {
        @Override
        public void onResponse(JSONArray response) {
            Log.i("Get_Response: ", response.toString());
        }
    },
    new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.i("Get_Error: ", error.toString());
        }
    }) {
    @Override
    public Map<String, String> getHeaders() throws AuthFailureError {
        Map<String, String> headers = new HashMap<>();
        headers.put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36");
        return headers;
    }
};

4. Test the Interface Outside Volley

First, confirm the PHP interface works correctly using a browser or Postman on a device in the same LAN. If you still get a 403 here, the issue is definitely server-side—double-check Apache's access logs (usually in /var/log/apache2/ on Linux or C:\xampp\apache\logs on Windows) for more details about the blocked request.

If the browser/Postman works but Volley doesn't, try clearing Volley's cache before adding the request:

requestQueue.getCache().clear();
requestQueue.add(request);

内容的提问来源于stack exchange,提问作者Ali Bavi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 09:34:31