HttpQueryInfo

This is a discussion on HttpQueryInfo within the C Programming forums, part of the General Programming Boards category; The code always fails in httpqueryinfo with an error code of 4262896. The rest of the code will just use ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    4

    HttpQueryInfo

    The code always fails in httpqueryinfo with an error code of 4262896. The rest of the code will just use InternetReadFile to download the html file. Its pointless though to continue until I figure out why httpqueryinfo fails.

    The purpose of httpqueryinfo is to get the size of the html site.

    Also, its not the website that I'm trying to access, I've been trying dozens of sites and the same error pops up.

    Code:
    hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
        if(hInternet == NULL)
        {
            printf("InternetOpen(%d", GetLastError);
            return EXIT_FAILURE;
        }
        
        hFile = InternetOpenUrl(hInternet, lpszUrl, NULL, 0, INTERNET_FLAG_RELOAD, 0);
        if(hInternet == NULL)
        {
            printf("InternetOpenUrl(%d)", GetLastError);
            return EXIT_FAILURE;
        }
        
        if(HttpQueryInfo(hFile, HTTP_QUERY_CONTENT_LENGTH, lpvBuffer, &lpdwBufferLength, NULL) == FALSE)
        {
            printf("HttpQueryInfo(%d)", GetLastError);
            return EXIT_FAILURE;
        }

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Do you have a variable named GetLastError or are you trying to call a function to find out an error code? If you are trying to call the function GetLastError(), call the function rather than refer to its address.
    Code:
    printf("HttpQueryInfo(%d)", GetLastError());
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    4
    I can't believe I didn't see that. No wonder the error kept coming out wrong. This time I called the function correctly and got this error:

    ERROR_HTTP_HEADER_NOT_FOUND
    12150
    The requested header could not be located.

    How can every site I try be missing its header?

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    I don't do Windows, so this is mostly a guess. Should one or more of these be hInternet instead?
    Code:
    hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
        if(hInternet == NULL)
        {
            printf("InternetOpen(%d", GetLastError());
            return EXIT_FAILURE;
        }
        
        hFile = InternetOpenUrl(hInternet, lpszUrl, NULL, 0, INTERNET_FLAG_RELOAD, 0);
        if(hInternet == NULL)
        {
            printf("InternetOpenUrl(%d)", GetLastError());
            return EXIT_FAILURE;
        }
        
        if(HttpQueryInfo(hFile, HTTP_QUERY_CONTENT_LENGTH, lpvBuffer, &lpdwBufferLength, NULL) == FALSE)
        {
            printf("HttpQueryInfo(%d)", GetLastError());
            return EXIT_FAILURE;
        }
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    4
    I went and double checked on msdn and I'm using the correct handles. Both are supposed to be hFile. Any other ideas?

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    I'm just goin' by the MSDN.
    Code:
    HINTERNET InternetOpen(
      LPCTSTR lpszAgent,
      DWORD dwAccessType,
      LPCTSTR lpszProxyName,
      LPCTSTR lpszProxyBypass,
      DWORD dwFlags
    );
    
    HINTERNET InternetOpenUrl(
      HINTERNET hInternet,
      LPCTSTR lpszUrl,
      LPCTSTR lpszHeaders,
      DWORD dwHeadersLength,
      DWORD dwFlags,
      DWORD_PTR dwContext
    );
    
    BOOL HttpQueryInfo(
      HINTERNET hRequest,
      DWORD dwInfoLevel,
      LPVOID lpvBuffer,
      LPDWORD lpdwBufferLength,
      LPDWORD lpdwIndex
    );
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  7. #7
    Registered User
    Join Date
    Aug 2005
    Posts
    4
    I'm 100% sure that the issue is not with the handles. Otherwise it would be giving me a completely different error. I think it has something to do with using the right flags. Has anybody ever done anything similiar to this and if yes, what flags did you use in your wininet functions.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21