Click here to Skip to main content
15,916,692 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionUpload a file in mfc through HTTP and not FTP Pin
Dhiraj kumar Saini20-Oct-08 22:35
Dhiraj kumar Saini20-Oct-08 22:35 
AnswerRe: Upload a file in mfc Pin
dehseth20-Oct-08 22:45
dehseth20-Oct-08 22:45 
GeneralRe: Upload a file in mfc Pin
Dhiraj kumar Saini20-Oct-08 22:56
Dhiraj kumar Saini20-Oct-08 22:56 
GeneralRe: Upload a file in mfc Pin
Prasann Mayekar20-Oct-08 23:45
Prasann Mayekar20-Oct-08 23:45 
GeneralRe: Upload a file in mfc Pin
Dhiraj kumar Saini20-Oct-08 23:52
Dhiraj kumar Saini20-Oct-08 23:52 
GeneralRe: Upload a file in mfc Pin
Prasann Mayekar21-Oct-08 0:52
Prasann Mayekar21-Oct-08 0:52 
GeneralRe: Upload a file in mfc Pin
Dhiraj kumar Saini21-Oct-08 2:54
Dhiraj kumar Saini21-Oct-08 2:54 
Questionwinhttp issue Pin
George_George20-Oct-08 22:23
George_George20-Oct-08 22:23 
Hello everyone,


Here is my code. My code is a client application which uses WinHttp to access http://connect.microsoft.com/dashboard, I tested with IE only if valid .Net Passport account is provided, the authentication could pass, or else can not access the service.

But I tested my below code, no matter I provide valie or invalid .Net Passport account, each time 200 OK is returned. Anyone has ideas why it always returns 200 OK?

#include <windows.h>
#include <Winhttp.h>
#include <stdio.h>

#pragma comment(lib,"Winhttp.lib")

void WinHttpAuthSample()
{
  DWORD dwStatusCode = 0;
  DWORD dwLastStatus = 0;
  DWORD dwSize = sizeof(DWORD);
  BOOL  bResults = FALSE;
  BOOL  bDone = FALSE;

  DWORD dwProxyAuthScheme = 0;
  HINTERNET  hSession = NULL, 
             hConnect = NULL,
             hRequest = NULL;

  hSession = WinHttpOpen( L"WinHTTP Example/1.0",  
                          WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
                          WINHTTP_NO_PROXY_NAME, 
                          WINHTTP_NO_PROXY_BYPASS, 0 );

  INTERNET_PORT nPort = INTERNET_DEFAULT_HTTPS_PORT;

  if( hSession )
    hConnect = WinHttpConnect( hSession, 
                               L"connect.microsoft.com", 
                               nPort, 0 );

  if( hConnect )
    hRequest = WinHttpOpenRequest( hConnect, 
                                   L"GET", 
                                   L"/dashboard",
                                   NULL, 
                                   WINHTTP_NO_REFERER, 
                                   WINHTTP_DEFAULT_ACCEPT_TYPES,
                                   WINHTTP_FLAG_SECURE);
  if( hRequest == NULL )
    bDone = TRUE;

  while( !bDone )
  {
    if( dwProxyAuthScheme != 0 )
      bResults = WinHttpSetCredentials( hRequest, 
                                        WINHTTP_AUTH_TARGET_PROXY, 
                                        dwProxyAuthScheme, 
                                        L"username@hotmail.com",
                                        L"passport password",
                                        NULL );
    bResults = WinHttpSendRequest( hRequest,
                                   WINHTTP_NO_ADDITIONAL_HEADERS,
                                   0,
                                   WINHTTP_NO_REQUEST_DATA,
                                   0, 
                                   0, 
                                   0 );

    if( bResults )
      bResults = WinHttpReceiveResponse( hRequest, NULL );

    if( !bResults && GetLastError( ) == ERROR_WINHTTP_RESEND_REQUEST)
        continue;

    if( bResults ) 
      bResults = WinHttpQueryHeaders( hRequest, 
                                      WINHTTP_QUERY_STATUS_CODE |
                                      WINHTTP_QUERY_FLAG_NUMBER,
                                      NULL, 
                                      &dwStatusCode, 
                                      &dwSize, 
                                      NULL );

    if( bResults )
    {
      switch( dwStatusCode )
      {
        case 200: 

		 printf( "The resource was successfully retrieved.\n" );
         bDone = TRUE;
         break;

        case 401:
         
          printf(" The server requires authentication. Sending credentials...\n" );

          bDone = TRUE;

          break;

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

          bDone = TRUE;
          break;

        default:
         
          printf("Error. Status code %d returned.\n", dwStatusCode);
          bDone = TRUE;
      }
    }

    dwLastStatus = dwStatusCode;

    if( !bResults ) 
        bDone = TRUE;
  }

  if( !bResults )
  {
    DWORD dwLastError = GetLastError( );
    printf( "Error %d has occurred.\n", dwLastError );
  }

  // Close any open handles.
  if( hRequest ) WinHttpCloseHandle( hRequest );
  if( hConnect ) WinHttpCloseHandle( hConnect );
  if( hSession ) WinHttpCloseHandle( hSession );
}

int main(int argc, char* argv[])
{
         WinHttpAuthSample();
         return 0;
}



thanks in advance,
George
Questionregards MicroSoft visual C++ certification Pin
raju000320-Oct-08 22:03
raju000320-Oct-08 22:03 
AnswerRe: regards MicroSoft visual C++ certification Pin
Rajesh R Subramanian20-Oct-08 22:06
professionalRajesh R Subramanian20-Oct-08 22:06 
GeneralRe: regards MicroSoft visual C++ certification Pin
raju000320-Oct-08 22:15
raju000320-Oct-08 22:15 
RantRe: regards MicroSoft visual C++ certification Pin
Rajesh R Subramanian20-Oct-08 22:25
professionalRajesh R Subramanian20-Oct-08 22:25 
JokeRe: regards MicroSoft visual C++ certification Pin
CPallini20-Oct-08 22:19
mveCPallini20-Oct-08 22:19 
GeneralRe: regards MicroSoft visual C++ certification Pin
Roger Stoltz20-Oct-08 22:25
Roger Stoltz20-Oct-08 22:25 
Question[Message Deleted] Pin
tom4_2520-Oct-08 20:49
tom4_2520-Oct-08 20:49 
AnswerRe: fatal error LNK1104: cannot open file 'msg_bus2005.lib' Pin
CPallini20-Oct-08 21:06
mveCPallini20-Oct-08 21:06 
GeneralRe: fatal error LNK1104: cannot open file 'msg_bus2005.lib' Pin
raju000320-Oct-08 22:06
raju000320-Oct-08 22:06 
QuestionRe: [Message Deleted] Pin
CPallini20-Oct-08 21:48
mveCPallini20-Oct-08 21:48 
QuestionCRecordSet::Update is failing Pin
V K 220-Oct-08 20:25
V K 220-Oct-08 20:25 
AnswerRe: CRecordSet::Update is failing Pin
CPallini20-Oct-08 21:03
mveCPallini20-Oct-08 21:03 
QuestionRe: CRecordSet::Update is failing Pin
Mark Salsbery21-Oct-08 5:12
Mark Salsbery21-Oct-08 5:12 
QuestionCrash when Clist is Destroyed in Vista Pin
Shaileshhex20-Oct-08 20:23
Shaileshhex20-Oct-08 20:23 
JokeRe: Crash when Clist is Destroyed in Vista Pin
CPallini20-Oct-08 21:01
mveCPallini20-Oct-08 21:01 
GeneralRe: Crash when Clist is Destroyed in Vista Pin
KarstenK20-Oct-08 21:25
mveKarstenK20-Oct-08 21:25 
GeneralRe: Crash when Clist is Destroyed in Vista Pin
Shaileshhex20-Oct-08 21:31
Shaileshhex20-Oct-08 21:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.