windows winhttp的编程例子,但是头文件和库文件,我的机子环境上没有,只有下载了头文件和库文件后才可以使用。

来源:互联网 发布:网络教学的哪些专业好 编辑:程序博客网 时间:2024/05/18 03:46
这是windows winhttp的编程例子,但是头文件和库文件,我的机子环境上没有,只有下载了头文件和库文件后才可以使用。
暂时先放置不管,作为记录,以后有精力再进行研究
#pragma onceclass CMyHttp{public:CMyHttp(void);public:~CMyHttp(void);};#include "StdAfx.h"#include "MyHttp.h"#include <iostream>#include <windows.h>#include <WinHttp.h>#pragma comment(lib, "WinHttp.lib")using namespace std;CMyHttp::CMyHttp(void){DWORD dwSize = 0;DWORD dwDownloaded = 0;LPSTR pszOutBuffer;BOOL  bResults = FALSE;HINTERNET  hSession = NULL, hConnect = NULL,hRequest = NULL;// Use WinHttpOpen to obtain a session handle.hSession = WinHttpOpen( L"WinHTTP Example/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.microsoft.com",INTERNET_DEFAULT_HTTPS_PORT, 0);// Create an HTTP request handle.if (hConnect)hRequest = WinHttpOpenRequest( hConnect, L"GET", NULL,NULL, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, WINHTTP_FLAG_SECURE);// Send a request.if (hRequest)bResults = WinHttpSendRequest( hRequest,WINHTTP_NO_ADDITIONAL_HEADERS, 0,WINHTTP_NO_REQUEST_DATA, 0, 0, 0);// End the request.if (bResults)bResults = WinHttpReceiveResponse( hRequest, NULL);// Continue to verify data until there is nothing left.if (bResults)do {// Verify available data.dwSize = 0;if (!WinHttpQueryDataAvailable( hRequest, &dwSize))printf("Error %u in WinHttpQueryDataAvailable.\n",GetLastError());// Allocate space for the buffer.pszOutBuffer = new char[dwSize+1];if (!pszOutBuffer){printf("Out of memory\n");dwSize=0;}else{// Read the Data.ZeroMemory(pszOutBuffer, dwSize+1);if (!WinHttpReadData( hRequest, (LPVOID)pszOutBuffer, dwSize, &dwDownloaded))printf("Error %u in WinHttpReadData.\n", GetLastError());elsecout << pszOutBuffer;// Free the memory allocated to the buffer.delete [] pszOutBuffer;}} while (dwSize>0);// Report any 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);}CMyHttp::~CMyHttp(void){}

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 脸突然长斑了怎么办 生气后脸上长斑怎么办 脸上长了座疮怎么办 喝了啤酒吃柿子怎么办 脸上长了痤疮该怎么办 脸上老长闭口痘怎么办 右脸颊一直长痘怎么办 痘痘粉刺反复长怎么办 长痘留下的红印怎么办 熬夜长出的痘痘怎么办 脸上两边长痘痘怎么办 我左脸比右脸大怎么办 左脸莫名肿了怎么办 牙疼得半边脸痛怎么办 手和脸突然发麻怎么办 右半边脸麻木了怎么办 左边脸突然肿了怎么办 左半边脸皮肤疼怎么办 脸内侧的肉肿了怎么办 上火引起的脸肿怎么办 脸肿里面有硬块怎么办 内分泌失调引起的肥胖怎么办 宝宝接种证丢了怎么办 不给补办接种证怎么办 儿童接种证丢了怎么办 疫苗接种本丢了怎么办 脊灰滴剂滴多了怎么办 鞋小了挤脚趾头怎么办 大母脚趾头疼是怎么办 小脚趾内侧长茧怎么办 小脚趾肿了很痛怎么办 穿袜子大脚趾痛怎么办 脚指头长水泡很痒怎么办 走路脚打起泡了怎么办 剪完脚趾甲肿了怎么办 大脚趾关节处疼怎么办 战士10穿不进去怎么办 脚上皮肤干燥起皮怎么办 脚趾头冻了很痒怎么办 大脚趾里面有脓怎么办 大脚趾肉肿了怎么办