Click here to Skip to main content
15,917,005 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralPlease help, i got problem with memory allocation Pin
Rassul Yunussov11-Mar-05 22:58
Rassul Yunussov11-Mar-05 22:58 
GeneralWorking with MS Word Pin
Zero_divide_111-Mar-05 20:44
Zero_divide_111-Mar-05 20:44 
Generaldiference between C++ and VC++ Pin
Anonymous11-Mar-05 19:42
Anonymous11-Mar-05 19:42 
GeneralRe: diference between C++ and VC++ Pin
Zero_divide_111-Mar-05 20:26
Zero_divide_111-Mar-05 20:26 
GeneralRe: diference between C++ and VC++ Pin
markkuk12-Mar-05 0:45
markkuk12-Mar-05 0:45 
GeneralRe: diference between C++ and VC++ Pin
deldeep12-Mar-05 2:59
deldeep12-Mar-05 2:59 
GeneralRe: diference between C++ and VC++ Pin
John R. Shaw12-Mar-05 13:46
John R. Shaw12-Mar-05 13:46 
GeneralaHelp with SSL through anuthenticating proxy in WinInet Pin
Nickmatic11-Mar-05 14:50
Nickmatic11-Mar-05 14:50 
Hi folks-
I've been searching for answers on this problem for days. Hope someone can help!!

I've got a very basic example application, taken directly from the WinInet HttpSendRequestEx() example on MSDN (http://support.microsoft.com/kb/q177188/). I have to use this function in my appication since a large amount of data must be sent.

My test program works perfectly except when Digest authentication and SSL are being used. In that case only, the call to InternetErrorDlg() raises an access violation exception inside the Wininet DLL.

No SSL works fine. Basic authentication works fine. SSL with Basic Authentication works fine. No SSL with Digest works fine!!!

I'm testing with a free Proxy server called FreeProxy, the only one I could find which supports both Basic and Digest authentication.

I discovered that the HTTP Status code must be checked right after the call to HttpSendRequestEx() (see the code). Code 407 (Proxy authentication required) is returned here when the proxy is running and the next call to InternetWriteFile() will fail.

One other thing I observed is that when using Digest the last call to InternetReadFile() (at the end) to retrieve the response hangs up for about 30 seconds before finally returning normally. This does not happen with Basic authentication.

So the question is... what is causing that access violation inside WinInet when I call InternetErrorDlg()???? Have tried this on Win 2000 and XP.

Also, if anyone knows of another authenticating proxy I can test with that would be great.

Thanks!!
-Nicholas

Here's my code:

BOOL bSecure = TRUE;

HINTERNET hConnect;
if (!bSecure)
hConnect = InternetConnect(hSession, "server.com", INTERNET_DEFAULT_HTTP_PORT,
NULL, NULL, INTERNET_SERVICE_HTTP,NULL, NULL);
else
hConnect = InternetConnect(hSession, "server.com", INTERNET_DEFAULT_HTTPS_PORT,
NULL, NULL, INTERNET_SERVICE_HTTP,NULL, NULL);

HINTERNET hRequest;
if (!bSecure)
hRequest = HttpOpenRequest(hConnect, "POST", "test.cgi",
NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
else
hRequest = HttpOpenRequest(hConnect, "POST", "test.cgi",
NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_SECURE, 0);

INTERNET_BUFFERS BufferIn;
DWORD dwBytesWritten;
int n;
BYTE pBuffer[1024];
BOOL bRet;

BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS ); // Must be set or error will occur
BufferIn.Next = NULL;
BufferIn.lpcszHeader = NULL;
BufferIn.dwHeadersLength = 0;
BufferIn.dwHeadersTotal = 0;
BufferIn.lpvBuffer = NULL;
BufferIn.dwBufferLength = 0;
BufferIn.dwBufferTotal = dwPostSize; // This is the only member used other than dwStructSize
BufferIn.dwOffsetLow = 0;
BufferIn.dwOffsetHigh = 0;

if(!HttpSendRequestEx( hRequest, &BufferIn, NULL, 0, 0)) {
printf( "Error on HttpSendRequestEx %d\n",GetLastError() );
return FALSE;
}

BOOL bHaveProxy = FALSE;

// get the http status code (if any)
DWORD dwStatusCode;
DWORD dwLength = sizeof(dwStatusCode);
if (HttpQueryInfo(hRequest, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &dwStatusCode, &dwLength, NULL) &&
dwStatusCode == 407)
bHaveProxy = TRUE; // we're connecting thru an authenticating proxy server

if (!bHaveProxy) { // call to InternetWriteFile() will fail with code 12019 if we got 407
FillMemory(pBuffer, 1024, 'D'); // fill buffer with meaninless data
bRet=TRUE;
for(n=1; n<=(int)dwPostSize/1024 && bRet; n++) {
if(bRet=InternetWriteFile( hRequest, pBuffer, 1024, &dwBytesWritten))
printf( "\r%d bytes sent.", n*1024);
}

if(!bRet) {
printf( "\nError on InternetWriteFile %lu\n",GetLastError() );
return FALSE;
}
}

if(!HttpEndRequest(hRequest, NULL, 0, 0)) {
printf( "Error on HttpEndRequest %lu \n", GetLastError());
return FALSE;
}

// get the http status code (if any)
dwLength = sizeof(dwStatusCode);
if (HttpQueryInfo(hRequest, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER,
&dwStatusCode, &dwLength, NULL) && dwStatusCode == 407)
bHaveProxy = TRUE;

// show the proxy login dialog if a proxy was detected (code 407)
if (bHaveProxy) {
// note: this call causes an access violation if using SSL with Digest authentication
InternetErrorDlg(GetDesktopWindow(), hRequest, ERROR_SUCCESS,
FLAGS_ERROR_UI_FILTER_FOR_ERRORS | FLAGS_ERROR_UI_FLAGS_GENERATE_DATA |
FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS, NULL);
}

// read response
DWORD dwBytesRead;
char pcBuffer[512];
printf("\nThe following was returned by the server:\n");
do {
dwBytesRead=0;
if (InternetReadFile(hRequest, pcBuffer, 511, &dwBytesRead)) {
pcBuffer[dwBytesRead]=0x00; // Null-terminate buffer
printf("%s", pcBuffer);
} else
printf("\nInternetReadFile failed");
} while (dwBytesRead>0);



Generalcritical error Pin
mpapeo11-Mar-05 13:00
mpapeo11-Mar-05 13:00 
GeneralRe: critical error Pin
John R. Shaw12-Mar-05 14:17
John R. Shaw12-Mar-05 14:17 
GeneralRe: critical error Pin
mpapeo13-Mar-05 11:16
mpapeo13-Mar-05 11:16 
GeneralRe: critical error Pin
John R. Shaw15-Mar-05 10:23
John R. Shaw15-Mar-05 10:23 
QuestionHow to check wheter a specified path is a dir? Pin
Member 1219625211-Mar-05 12:32
Member 1219625211-Mar-05 12:32 
AnswerRe: How to check wheter a specified path is a dir? Pin
PJ Arends11-Mar-05 12:41
professionalPJ Arends11-Mar-05 12:41 
AnswerRe: How to check wheter a specified path is a dir? Pin
Ravi Bhavnani11-Mar-05 14:42
professionalRavi Bhavnani11-Mar-05 14:42 
AnswerRe: How to check wheter a specified path is a dir? Pin
Michael Dunn11-Mar-05 15:15
sitebuilderMichael Dunn11-Mar-05 15:15 
GeneralGetting rights for OpenSCManager Pin
bepperso11-Mar-05 11:02
bepperso11-Mar-05 11:02 
Generaldisplay a html page which is in memory Pin
includeh1011-Mar-05 10:31
includeh1011-Mar-05 10:31 
GeneralRe: display a html page which is in memory Pin
Ravi Bhavnani11-Mar-05 10:55
professionalRavi Bhavnani11-Mar-05 10:55 
Generalmemory allocation in dll Pin
NMiceli11-Mar-05 8:59
NMiceli11-Mar-05 8:59 
GeneralRe: memory allocation in dll Pin
Chris Losinger11-Mar-05 9:43
professionalChris Losinger11-Mar-05 9:43 
GeneralRe: memory allocation in dll Pin
NMiceli11-Mar-05 10:30
NMiceli11-Mar-05 10:30 
GeneralRe: memory allocation in dll Pin
cmk11-Mar-05 15:56
cmk11-Mar-05 15:56 
GeneralRe: memory allocation in dll Pin
Anonymous11-Mar-05 16:10
Anonymous11-Mar-05 16:10 
GeneralRe: memory allocation in dll Pin
cmk11-Mar-05 17:13
cmk11-Mar-05 17:13 

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.