C++ http请求
2016-01-03 00:55
555 查看
实例 代码
#include "stdafx.h" #include <stdio.h> #include <windows.h> #include <wininet.h> #include <iostream> #include <string> using namespace std; #define MAXSIZE 1024 #pragma comment(lib, "Wininet.lib") bool Urlopen(const _TCHAR* url, BYTE *&urlContent) { HINTERNET hSession = InternetOpen(_T("UrlTest"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); if(hSession != NULL) { HINTERNET hHttp = InternetOpenUrl(hSession, url, NULL, 0, INTERNET_FLAG_DONT_CACHE, 0); if (hHttp != NULL) { urlContent = new (std::nothrow) BYTE[MAXSIZE]; if(NULL == urlContent) { return false; } memset(urlContent, 0, MAXSIZE); ULONG Number = 1; bool bInternetReadFile = false; bInternetReadFile = InternetReadFile(hHttp, urlContent, MAXSIZE - 1, &Number); if(!bInternetReadFile) { return false; } if(Number <= 0 || Number >= <span style="font-family: Arial, Helvetica, sans-serif;">MAXSIZE</span>) { return false; } urlContent[Number] = '\0'; InternetCloseHandle(hHttp); hHttp = NULL; return true; } InternetCloseHandle(hSession); hSession = NULL; } return false; } int _tmain(int argc, _TCHAR* argv[]) { wstring wstr = _T("http://120.25.242.254/WxService/test?UserId=niebingyu&OrgCode=YUTONGXUN5.0"); BYTE* byte = NULL; bool bUrlopen = false; bUrlopen = Urlopen(wstr.c_str(), byte); if(NULL == byte) { cout<<"byte is NULL"<<endl; return 0; } if(!bUrlopen) { cout<<"Urlopen return false"<<endl; return 0; } cout<<byte<<endl; if(NULL != byte) { delete byte; byte = NULL; } return 0; }
相关文章推荐
- httpClient4.3x版本的简单使用
- HTTP Status 400 -
- (一)TCP编程-线程客户端与服务端的交流
- HttpApache下载数据
- HttpHttpApache两种上传方法
- 对称与非对称加密;SSL;HTTPS;AJP
- 网络基础
- 网络基础,
- 一个易用的轻量级的网络爬虫(Easy to use lightweight web crawler)
- QT读取网络图片
- 4.虚拟机ubuntu网络问题汇总
- 网络安全
- 个人笔记——Android网络技术
- 如何学习ios(摘自知乎https://www.zhihu.com/question/20016551)
- iOS手势操作,拖动,轻击,捏合,旋转,长按,自定义(http://www.cnblogs.com/huangjianwu/p/4675648.html)
- epoll:EPOLLLT模式下的正确读写方式
- Java学习笔记(二)-------客户端一对多(TCP)多人聊天小程序
- IOS绘图详解(http://blog.163.com/wkyuyang_001/blog/static/10802122820133190545227/)
- MacOS X快捷键一览(http://www.cnblogs.com/ios8/p/Mac-OSX-keyword-cmd.html)
- 实现客户端和服务器双向的防重放攻击