Hi,
I have asked StackOverflow, compared my code to multiple different online sources, but I still cannot get the page status from the server.

The library I am using is Wininet, and the function failing to retrieve the correct data is HttpQueryInfo. I am linking against wininet.

Code:

int statusCode;
    DWORD statCharLen = 128;
    char statChar[statCharLen];

    //Check existance of page (for 404 error)
    if(!HttpQueryInfo(hRequestHandle,
                      HTTP_QUERY_STATUS_CODE,
                      &statChar,
                      &statCharLen,
                      NULL))
        return 4;
    statusCode = atoi(statChar);

    if(statusCode == 404)
        cout << "We got a 404 error" << endl;

    cout << "Stat code text : " << statChar << endl;
    cout << "Stat code num  : " << statusCode << endl;
    cout << "404 status code: " << HTTP_STATUS_NOT_FOUND << endl;

The problem is I am not able to retrieve a status code; the query simply returns a 1 byte char array containing "0". I am not sure what to make of this (by the way, this code was semi-influenced by one of the stackoverflow answers, but still does not work).

Thanks for your help!
If I was unclear about anything comment and I'll fix it.

So, no one?
This seems like a difficult question, or maybe I just worded it wrong, but its been a week now and SO hasn't been able to answer it either.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.