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

配置自定义代理后RestAssured代码执行出现407授权错误求助

代理环境下RestAssured请求返回407错误求助

我是RestAssured API测试的新手,目前在代理环境中测试接口,已经在代码里配置了代理信息,但执行时始终返回407 Proxy Authentication Required错误。

尝试的第一种代码写法

RequestSpecification httpRequest = RestAssured.given().relaxedHTTPSValidation()
        .proxy("hostname", 8080).auth().preemptive().basic("username", "password");
Response res = httpRequest.get("https://api.zippopotam.us/us/90210");
ResponseBody body = res.body();
res.statusCode();

String rbdy = body.asString();
System.out.println("Data from the GET API- " + rbdy);
System.out.println("Status code  : " +  res.statusCode());

执行后输出:

Status code : 407

Postman对比测试

使用和代码中完全相同的代理主机、端口、用户名密码配置,在Postman中发送相同请求,能够正常获取返回结果,无407错误。

尝试的第二种代码写法

RestAssured.proxy("host", 8080);
RestAssured.basic("username", "password");
// Authentication API is outside network and requires proxy

given().when().get("https://api.zippopotam.us/us/90210").then().statusCode(200);

执行后同样返回407错误,断言失败。

其他尝试的解决方法

  • 在Eclipse的全局设置中配置代理信息,无效
  • 修改JRE安装目录下net.properties文件,设置java.net.useSystemProxies=true,无效果
  • 通过System.setProperty设置代理参数(包括用户名密码),依然返回407:
System.setProperty("https.proxyHost", "host");
System.setProperty("https.proxyPort", "8080");
System.setProperty("https.proxyUser", "username");
System.setProperty("https.proxyPassword", "password");

恳请各位帮忙排查问题,解决这个407代理认证失败的问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 20:24:31