V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
PepperEgg
V2EX  ›  问与答

https 请求通过 http 代理关于“Proxy-Authorization”头添加不上的问题

  •  
  •   PepperEgg · 2022-11-14 17:08:21 +08:00 · 328 次点击
    这是一个创建于 500 天前的主题,其中的信息可能已经有所发展或是发生改变。
    先举两个 http 代理请求例子:
    ====
    curl 的 : curl -U user:password -x your.com:1000 https://myip.ipip.net
    ====
    python 的:
    import requests
    proxies =
    {
    "https":"http://user:password:@your.com:1000"
    }
    rsp = requests.get("https://myip.ipip.net/",proxies=proxies)
    print(rsp.text)
    ====
    上面的俩例子通过抓包,可以抓到,首次请求就包含了 Proxy-Authorization 并且访问的 myip.ipip.net:443 。然后后面的包就是 https 请求那一套了。

    但是我自己写代码就出问题了,首次请求带不上去 Proxy-Authorization 。

    其实就是代理验证的场景,用户使用我们软件,我们需要检测一下用户自己的代理服务器是否可用。
    目前遇到的问题是,自己写代码,https 请求通过 http 代理,怎么都加不上。http 请求就完全没问题。
    目前是 c++开发的项目,用了 libcurl ,Qt 自带 network 这俩,手动添加 header ,都不行,http 下是完全没问题的。

    目前很多用户用的代理服务器,仅支持 header 带 Proxy-Authorization 的模式,如果用 code 407 响应 很多服务器都是直接关闭链接,不处理后续发过去的带验证账号密码的响应 QAQ 。

    求大佬解惑如何处理。
    (有 c++代码示例最好~)


    我的 libcurl 添加头方法:
    struct curl_slist *headers = nullptr;
    headers = curl_slist_append(headers, "Proxy-Authorization: Basic xxxxxxxxxx");
    julyclyde
        1
    julyclyde  
       2022-11-15 09:12:01 +08:00
    没太看懂你的描述

    客户端 经过 http (非 ssl )的代理服务器 访问 https 服务器
    其中代理服务器需要认证用户名密码

    问的是,代理服务器这一步没发认证,还是 https 这一步没发认证呢?

    你的 libcurl 代码,我感觉好像把认证 header 发给 https 那边去了
    PepperEgg
        2
    PepperEgg  
    OP
       2022-11-15 13:55:59 +08:00
    @julyclyde 已经解决了。。。是我代码逻辑问题 T.T 简单来说就是看岔了。。。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2927 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 15:10 · PVG 23:10 · LAX 08:10 · JFK 11:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.