This code previously worked on a ... 'project' of mine. Now though it fails to send request and returns error 997 (IO_PENDING).
Code:// ........ Kuwait.cpp : Defines the entry point for the console application. // #include <windows.h> #include <wininet.h> #include <stdio.h> BYTE pBuffer[1048576]; int main(int argc, char* argv[]){ DWORD BytesRead = 0; printf("Opening internet..."); HINTERNET hInternet = InternetOpen(L"FreeSpeech" , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , INTERNET_FLAG_ASYNC); if(hInternet != NULL){ printf("done.\nOpening connection..."); } else { printf("FAILED.\n"); return 0; } HINTERNET hConnect = InternetConnect(hInternet , L"134.225.36.80" , INTERNET_DEFAULT_HTTP_PORT , L"anonymous" , NULL , INTERNET_SERVICE_HTTP , 0 , NULL); // http://www.unitednetworks.com.kw if(hConnect != NULL){ printf("done.\nOpening request..."); } else { printf("FAILED.\n"); return 0; } HINTERNET hRequest = HttpOpenRequest(hConnect , NULL , L"134.225.36.80/integers/?num=10&min=1&max=6&col=1&base=10&format=plain&rnd=new" , NULL , NULL , NULL , INTERNET_FLAG_RELOAD , NULL); if(hRequest != NULL){ printf("done.\n"); } else { printf("FAILED.\n"); return 0; } start: BOOL bSend = HttpSendRequest(hRequest , NULL , -1L , NULL , 0); if(bSend){ printf("Request Sent.\n"); } else { printf("Failed to send request.\n"); printf("Errorcode = %d\n" , GetLastError()); Sleep(1000); goto start; //return 0; } BOOL bRead; while(BytesRead == 0){ bRead = InternetReadFile(hRequest , pBuffer , 1048576 , &BytesRead); Sleep(0); } printf("%d bytes read.\n" , BytesRead); BOOL bClose = InternetCloseHandle(hRequest); FILE* pFile = fopen("test.txt" , "w+b"); fwrite((VOID*)pBuffer , 1048576, 1 , pFile); fclose(pFile); return 0; }



LinkBack URL
About LinkBacks



