gpt4 book ai didi

c++ - 无法发送代理凭据 (407)

转载 作者:可可西里 更新时间:2023-11-01 17:03:25 24 4
gpt4 key购买 nike

我正在尝试编写与需要密码和用户名身份验证的代理连接的 C++ 代码程序 (ip:port:username:pw) 我可以使用 http,但是当我使用 https 时,我总是收到 407 错误。

如何以正确的方式在 https 上发送代理凭据? (C++)

最佳答案

很好,因为状态 407 表示代理需要身份验证。

所以你可以使用这个:

    case 407:
// The proxy requires authentication.
printf( "The proxy requires authentication. Sending credentials...\n" );

// Obtain the supported and preferred schemes.
bResults = WinHttpQueryAuthSchemes( hRequest,
&dwSupportedSchemes,
&dwFirstScheme,
&dwTarget );

// Set the credentials before resending the request.
if( bResults )
dwProxyAuthScheme = ChooseAuthScheme(dwSupportedSchemes);

// If the same credentials are requested twice, abort the
// request. For simplicity, this sample does not check
// for a repeated sequence of status codes.
if( dwLastStatus == 407 )
bDone = TRUE;
break;

函数

    DWORD ChooseAuthScheme( DWORD dwSupportedSchemes )
{
// It is the server's responsibility only to accept
// authentication schemes that provide a sufficient
// level of security to protect the servers resources.
//
// The client is also obligated only to use an authentication
// scheme that adequately protects its username and password.
//
// Thus, this sample code does not use Basic authentication
// becaus Basic authentication exposes the client's username
// and password to anyone monitoring the connection.

if( dwSupportedSchemes & WINHTTP_AUTH_SCHEME_NEGOTIATE )
return WINHTTP_AUTH_SCHEME_NEGOTIATE;
else if( dwSupportedSchemes & WINHTTP_AUTH_SCHEME_NTLM )
return WINHTTP_AUTH_SCHEME_NTLM;
else if( dwSupportedSchemes & WINHTTP_AUTH_SCHEME_PASSPORT )
return WINHTTP_AUTH_SCHEME_PASSPORT;
else if( dwSupportedSchemes & WINHTTP_AUTH_SCHEME_DIGEST )
return WINHTTP_AUTH_SCHEME_DIGEST;
else
return 0;
}

这决定了身份验证方案......然后你使用

    bResults = WinHttpSetCredentials( hRequest, 
WINHTTP_AUTH_TARGET_SERVER,
dwProxyAuthScheme,
username,
password,
NULL );

我希望这会有所帮助...我也在使用这些工具从 Azure 市场连接到 Microsoft 翻译器,因为它移到了那里,并且从 8 月开始所有旧的必应翻译器都不会收到请求。对我来说,它是通过 header 发送身份验证 key 。但我猜你有用户名和密码。

关于c++ - 无法发送代理凭据 (407),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11337824/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com