首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

使用httpOpenRequest怎么发送GET方法呢

2012-01-10 
使用httpOpenRequest如何发送GET方法呢hRequestHttpOpenRequest(hConnect,TEXT( GET ),NULL,TEXT( HTT

使用httpOpenRequest如何发送GET方法呢
hRequest   =   HttpOpenRequest   (  
  hConnect,  
  TEXT( "GET "),  
  NULL,  
  TEXT( "HTTP/1.1 "),  
  NULL,  
  (LPCTSTR*)AcceptTypes,  
  dwFlags,   0  
      );
if(!hRequest)
goto   end;

if(!HttpSendRequest   (hRequest,   data,   datalen,   NULL,   0   ))
goto   end;

这段代码对么....

[解决办法]
你试下不就知道了。。。

HINTERNET hSession = ::InternetOpen( "MSDN SurfBear ",
PRE_CONFIG_INTERNET_ACCESS,
NULL,
INTERNET_INVALID_PORT_NUMBER,
0) ;

// Connect to www.microsoft.com.
HINTERNET hConnect = ::InternetConnect(hSession,
"news.163.com ",
INTERNET_INVALID_PORT_NUMBER,
" ",
" ",
INTERNET_SERVICE_HTTP,
0,
0) ;

// Request the file /MSDN/MSDNINFO/ from the server.
HINTERNET hHttpFile = ::HttpOpenRequest(hConnect,
"GET ",
"/domestic ",
HTTP_VERSION,
NULL,
0,
INTERNET_FLAG_DONT_CACHE,
1);

// Send the request.
BOOL bSendRequest = ::HttpSendRequest(hHttpFile, NULL, 0, 0, 0);

// Get the length of the file.
char bufQuery[32] ;
DWORD dwLengthBufQuery = sizeof(bufQuery);
BOOL bQuery = ::HttpQueryInfo(hHttpFile, HTTP_QUERY_CONTENT_LENGTH,bufQuery,&dwLengthBufQuery,NULL) ;

// Convert length from ASCII string to a DWORD.
DWORD dwFileSize = (DWORD)atol(bufQuery) ;

// Allocate a buffer for the file.
char* buffer = new char[dwFileSize+1] ;

// Read the file into the buffer.
DWORD dwBytesRead ;
BOOL bRead = ::InternetReadFile(hHttpFile,
buffer,
dwFileSize+1,
&dwBytesRead);
// Put a zero on the end of the buffer.
AfxMessageBox(buffer);
buffer[dwBytesRead] = 0 ;

热点排行