我正在尝试使用WININET从C ++中的URL检索HTTP响应代码。每当我使用下面的代码时,它总是返回2或4,而不是200或404等。请告诉我这里我做错了什么:
HINTERNET hOpen;
HINTERNET hFile;
hOpen = InternetOpenA("MYAPP", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
char* url = "http://www.google.com/";
hFile = InternetOpenUrlA(hOpen, url, NULL, 0,INTERNET_FLAG_RELOAD, 0);
char responseText[256]; // change to wchar_t for unicode
DWORD responseTextSize = sizeof(responseText);
if(!HttpQueryInfo(hFile,HTTP_QUERY_STATUS_CODE,&responseText,&responseTextSize,NULL)) {
return -1.0;
}
cout << "Response: " << responseText << " ";