How to read HTTP response body when status code is not 200 (e.g. 406)?

I send a POST message to the server:

ih = InternetPostRequest( url, post_text,  
   INTERNET_FLAG_TRANSFER_ASCII 
   |INTERNET_FLAG_KEEP_CONNECTION
);
if( ih )
{
    while( ( resp = InternetReadString( ih ) ) != "" )
    {
        _TRACE( "Response: " + resp );
    }

    _TRACE( "Status code : " + InternetGetStatusCode( ih ) );
    InternetClose( ih );
}
else
{
    printf( "Internet connection can not be open because: %s", GetLastOSError() );
}

Is it possible to read the server response when an error occurs, e.g. 406? It seems to me that InternetReadString reads the "Response" only when the status is 200. I would also like to get the HTTP error code.

InternetReadString reads whatever server responds with. Some servers provide so called error pages, some only report error code. That depends on server.

Isn’t it true that if InternetPostRequest fails (for example with a 406 error), it won’t return ih, and without ih I won’t be able to call InternetGetStatusCode?

It depends on what the error code is. There are many different error codes and servers react differently too. You have to test your specific use case with particular server. There is also getlastoserror that doesn't depend on internet handle.