1

I am trying do code C++ program that connects with a proxy which needs password and username authentication (ip:port:username:pw) I got http working but when I am using https I always getting a 407 error.

How do I send the proxy credentials on https the right way? (C++)

4

1 に答える 1

3

ステータス 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トランスレーターに接続しています. 私にとっては、ヘッダーを介して認証キーを送信することです。しかし、ユーザー名とパスワードを持っていると思います。

于 2012-07-05T12:30:33.277 に答える