winnet api 实现Get请求

这篇博客记录了如何利用WinAPI函数进行HTTP GET请求的实现,以获取www.hao123.com上的/task.asp?uid=123页面的内容。
摘要由CSDN通过智能技术生成

mark一下!

#include <windows.h>
#include <WinInet.h>
#include <string>

using namespace std;

#pragma comment(lib,"wininet.lib")

char* GetUrl2(const char* strName,char* strObject)
{
	HINTERNET hSession = ::InternetOpen("MSDN SurfBear", 
		PRE_CONFIG_INTERNET_ACCESS, 
		NULL, 
		INTERNET_INVALID_PORT_NUMBER, 
		0) ; 

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

	// Request the file /MSDN/MSDNINFO/ from the server. 
	HINTERNET hHttpFile = ::HttpOpenRequest(hConnect, 
		"GET", 
		strObject,
		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(b
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值