Skip to content

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

Description

@wslyx

简要描述

使用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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions