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

Java程序访问Intel指定URL返回403但浏览器可正常访问的问题求助

解决Java访问Intel页面返回403的问题

403禁止访问通常是网站反爬机制识别出请求并非来自真实浏览器,以下是针对性的解决方法:

1. 更新User-Agent到最新版本

你当前使用的Chrome 58版本过于老旧,极易被反爬规则拦截。换成当前主流的Chrome User-Agent,示例:

conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36");

2. 补充现代浏览器专属请求头

很多网站会校验Sec-开头的请求头,这些是现代浏览器默认发送的标识。你可以打开Chrome开发者工具的Network面板,复制目标页面的完整请求头,补充到代码中,比如:

conn.setRequestProperty("Sec-Fetch-Dest", "document");
conn.setRequestProperty("Sec-Fetch-Mode", "navigate");
conn.setRequestProperty("Sec-Fetch-Site", "none");
conn.setRequestProperty("Sec-Fetch-User", "?1");
conn.setRequestProperty("Upgrade-Insecure-Requests", "1");

3. 添加Referer头

部分网站会验证请求的来源页面,你可以设置Referer为Intel的产品主页或相关列表页:

conn.setRequestProperty("Referer", "https://www.intel.com/content/www/us/en/products/chipsets.html");

4. 启用自动重定向并处理Cookie

  • 开启HttpURLConnection的自动重定向功能:
conn.setInstanceFollowRedirects(true);
  • 若网站依赖Cookie验证会话,先在Chrome中访问目标页面,复制Cookie字符串后添加到请求头:
conn.setRequestProperty("Cookie", "这里粘贴从Chrome获取的Cookie内容");

注意:Cookie存在过期可能,长期使用建议用CookieManager自动管理会话Cookie。

修改后的完整示例代码

String url = "https://www.intel.com/content/www/us/en/products/sku/218824/intel-w790-chipset/specifications.html";

try {
    URL obj = new URL(url);
    HttpURLConnection conn = (HttpURLConnection) obj.openConnection();

    // 开启自动重定向
    conn.setInstanceFollowRedirects(true);
    conn.setRequestMethod("GET");

    // 配置请求头
    conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36");
    conn.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
    conn.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
    conn.setRequestProperty("Accept-Encoding", "gzip, deflate, br");
    conn.setRequestProperty("Connection", "keep-alive");
    conn.setRequestProperty("Referer", "https://www.intel.com/content/www/us/en/products/chipsets.html");
    conn.setRequestProperty("Sec-Fetch-Dest", "document");
    conn.setRequestProperty("Sec-Fetch-Mode", "navigate");
    conn.setRequestProperty("Sec-Fetch-Site", "none");
    conn.setRequestProperty("Sec-Fetch-User", "?1");
    conn.setRequestProperty("Upgrade-Insecure-Requests", "1");
    // 替换为你从Chrome获取的Cookie
    conn.setRequestProperty("Cookie", "your-cookie-string-here");

    int responseCode = conn.getResponseCode();
    System.out.println("Response Code: " + responseCode);

    // 后续处理响应内容...
} catch (Exception e) {
    e.printStackTrace();
}

额外注意事项

  • 不要频繁发送请求,避免触发IP封禁;
  • 若以上方法无效,可能网站启用了Cloudflare等高级反爬机制,可考虑用Selenium、Playwright等工具模拟真实浏览器行为;
  • 确保爬虫行为符合Intel网站的Robots协议和使用条款。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 05:27:36