这个程序是我复制MSDN里的示例代码,只是修改了WinHttpOpenRequest的网站为Google。但是报错,ERROR_WINHTTP_CANNOT_CONNECT(12029),无法连接。请大家看看、帮忙编译一下看看是什么问题。谢谢了。
// WinHttp.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <Tchar.h>#include <windows.h>
#include <Winhttp.h>
#pragma comment(lib,"Winhttp.lib")#include <iostream>
using namespace std;int _tmain(int argc, _TCHAR* argv[])
{

    BOOL  bResults = FALSE;
    HINTERNET hSession = NULL,
hConnect = NULL,
hRequest = NULL;

    // Use WinHttpOpen to obtain a session handle.
    hSession = WinHttpOpen(  L"A WinHTTP Example Program/1.0", 
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME, 
WINHTTP_NO_PROXY_BYPASS, 0);

    // Specify an HTTP server.
    if (hSession)
        hConnect = WinHttpConnect( hSession, L"www.google.cn",
INTERNET_DEFAULT_HTTP_PORT, 0);

    // Create an HTTP Request handle.
    if (hConnect)
        hRequest = WinHttpOpenRequest( hConnect, L"GET", 
L"/", 
NULL, WINHTTP_NO_REFERER, 
WINHTTP_DEFAULT_ACCEPT_TYPES, 
0);

    // Send a Request.
    if (hRequest) 
        bResults = WinHttpSendRequest( hRequest, 
WINHTTP_NO_ADDITIONAL_HEADERS,
0, WINHTTP_NO_REQUEST_DATA, 0, 
0, 0);

    // Place additional code here.
if (bResults)
{
#define BUFFER_SIZE 1024
DWORD dwNumberOfBytesRead;
string strResult;
char* sz=new char[BUFFER_SIZE];
memset(sz,0,BUFFER_SIZE);
do
{
bResults = WinHttpReadData(hRequest,sz,BUFFER_SIZE-1,&dwNumberOfBytesRead);
sz[dwNumberOfBytesRead]='\0';
strResult+=sz;
memset(sz,0,BUFFER_SIZE);
}
while(bResults && dwNumberOfBytesRead != 0);
delete[] sz;
sz=NULL;
if (bResults)
printf("%s\n",strResult.c_str());
}

    // Report errors.
    if (!bResults)
        printf("Error %d has occurred.\n",GetLastError());

    // Close open handles.
    if (hRequest) WinHttpCloseHandle(hRequest);
    if (hConnect) WinHttpCloseHandle(hConnect);
    if (hSession) WinHttpCloseHandle(hSession);


return 0;
}