Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用http代理时且需认证时,http客户端认证头设置错误 #3515

Open
wslyx opened this issue Feb 27, 2025 · 1 comment
Open

Comments

@wslyx
Copy link
Contributor

wslyx commented Feb 27, 2025

简要描述

使用http代理时且需认证时,http客户端认证头设置错误

模块版本情况

  • WxJava 模块名: wx-java-mp-spring-boot-starter-4.6.5.B WxMpServiceOkHttpImpl
  • WxJava 版本号:4.6.5.B

详细描述

clientBuilder.authenticator(new Authenticator() {
                public Request authenticate(Route route, Response response) throws IOException {
                    String credential = Credentials.basic(WxMpServiceOkHttpImpl.this.httpProxy.getProxyUsername(), WxMpServiceOkHttpImpl.this.httpProxy.getProxyPassword());
                    return response.request().newBuilder().header("Authorization", credential).build();
                }
            });

修正意见:

Tinyproxy 默认情况下 ​不支持直接修改认证请求头(如 Proxy-Authorization)的名称或格式,其认证机制严格遵循 HTTP 协议标准。以下是详细分析和替代方案:

​1. Tinyproxy 的认证头固定性
​标准协议约束​
Tinyproxy 的认证流程基于 HTTP 协议规范,使用固定的请求头和响应头:

代理要求认证时返回:Proxy-Authenticate: Basic realm="..."
客户端提交凭证时携带:Proxy-Authorization: Basic <credentials>

日志

me.chanjar.weixin.common.error.WxRuntimeException: java.io.IOException: Failed to authenticate with proxy
	at me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl.getAccessToken(BaseWxMpServiceImpl.java:287)
	at me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl.executeInternal(BaseWxMpServiceImpl.java:471)
	at me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl.execute(BaseWxMpServiceImpl.java:435)
	at me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl.post(BaseWxMpServiceImpl.java:383)
	at me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl.post(BaseWxMpServiceImpl.java:398)
	at me.chanjar.weixin.mp.api.impl.WxMpFreePublishServiceImpl.getPublicationRecords(WxMpFreePublishServiceImpl.java:64)
	at me.chanjar.weixin.mp.api.impl.WxMpFreePublishServiceImpl.getPublicationRecords(WxMpFreePublishServiceImpl.java:70)
	at cn.iocoder.yudao.module.mp.controller.admin.news.MpFreePublishController.getFreePublishPage(MpFreePublishController.java:55)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:355)

@wslyx
Copy link
Contributor Author

wslyx commented Feb 27, 2025

//设置授权
clientBuilder.proxyAuthenticator()

设置授权的方法也用错了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant