WinINet function(2)Request
2011-11-27 22:06 Clingingboy 阅读(549) 评论(0) 编辑 收藏 举报
参考此文档:http://wenku.baidu.com/view/4f3558edf8c75fbfc77db229.html
参考:http://wenku.baidu.com/view/b5364b87ec3a87c24028c438.html
InternetOpenUrl的内部
1.InternetConnect
Opens an File Transfer Protocol (FTP), Gopher, or HTTP session for a given site.
2.HttpOpenRequest
Creates an HTTP request handle.
3.HttpSendRequest
Sends the specified request to the HTTP server.
4.HttpQueryInfo
Retrieves header information associated with an HTTP request.
Demo
HINTERNET hInternet = InternetOpen("HttpAuth Sample", // app name
INTERNET_OPEN_TYPE_PRECONFIG, // access type
NULL, // proxy server
0, // proxy port
0); // flags
HINTERNET hConnect = ::InternetConnect(hInternet,
"www.microsoft.com",
INTERNET_INVALID_PORT_NUMBER,
"",
"",
INTERNET_SERVICE_HTTP,
0,
0) ;
HINTERNET hHttpFile = ::HttpOpenRequest(hConnect,
"GET",
"/MSDN/MSDNINFO/",
HTTP_VERSION,
NULL,
0,
INTERNET_FLAG_DONT_CACHE,
0) ;
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);
buffer[dwBytesRead] = 0 ;
Other functions
HttpAddRequestHeaders
Adds one or more HTTP request headers to the HTTP request handle.
参考:http://www.cnblogs.com/songsu/articles/1346782.html
InternetSetCookie
Creates a cookie associated with the specified URL.
InternetGetCookie
Retrieves the cookie for the specified URL.
BOOL res=InternetSetCookie("http://www.microsoft.com","a","test");
TCHAR cookie[1024];
DWORD leh;
res=InternetGetCookie("http://www.microsoft.com",NULL,cookie,&leh);
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现