SendRequest error 12007
ERROR_INTERNET_NAME_NOT_RESOLVED
The server name could not be resolved
Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.
View products that this article applies to.
hConnect = InternetConnect(hOpen, "www.microsoft.com", INTERNET_DEFAULT_HTTP_PORT,
NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
// SimpleGet.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
HINTERNET hOpen, hConnect, hReq;
hOpen = InternetOpen("SimpleGet", INTERNET_OPEN_TYPE_PRECONFIG, NULL, 0, 0);
if(!hOpen)
{
cout << "hopen " << GetLastError() << endl;
return 0;
}
// try the following in InternetConnect to see the problem.
hConnect = InternetConnect(hOpen, "www.microsoft.com/learning/", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
if(!hConnect)
{
cout << "hconnect " << GetLastError() << endl;
return 0;
}
hReq = HttpOpenRequest(hConnect, "GET", "", "HTTP/1.1", NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
if(!hReq)
{
cout << "hreq " << GetLastError() << endl;
return 0;
}
if(HttpSendRequest(hReq, NULL, 0, NULL, 0))
{
DWORD dwSize = 0;
char Data[1024] = "\0";
DWORD dwCode, dwCodeSize;
dwCodeSize = sizeof(DWORD);
if(!HttpQueryInfo(hReq, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &dwCode, &dwCodeSize, NULL))
{
cout << "queryinfo " << GetLastError() << endl;
return 0;
}
else
{
cout << "Status Code: " << dwCode << endl;
}
do
{
InternetReadFile(hReq, (LPVOID)Data, 1023, &dwSize);
if(0!=dwSize)
{
Data[dwSize]='\0';
cout << Data;
}
ZeroMemory(Data, 1024);
}while (dwSize !=0);
}
else
{
cout << "SendRequest error " << GetLastError() << endl;
}
return 0;
}
#include <windows.h>
#include <WinINet.h>
Keywords: KB839873, kbprb, kbinetdev, kbapi, kbpatch, kbwebbrowser, kbtshoot