UnOnline.cpp
来源:互联网 发布:tomcat绑定域名 编辑:程序博客网 时间:2024/04/30 12:02
#include <iostream>#include <string>#include <windows.h>#include <wininet.h>/*#pragma comment(lib,"WinInet")*/ /// Use this in VC++using namespace std;int main(){ LPCSTR lpszAccept[]= { "*/*" /// Accept types }, lpszAgent="Mozilla/4.0 (Compatible; MSIE 6.0;)", /// Agent name lpszHeader="Content-Type: application/x-www-form-urlencoded\r\n"; /// Addition header (Content type) /// Post data string lpPostData="action=unonline_user_mac&type=1&mac_ip=",IPAddr; cout<<"Please input the IP address: "; cin>>IPAddr; lpPostData.append(IPAddr); /// Initialize the use of the WinINet functions HINTERNET hInternet=InternetOpen( lpszAgent, INTERNET_OPEN_TYPE_DIRECT, NULL, INTERNET_INVALID_PORT_NUMBER, 0 ); /// Open an FTP or HTTP session HINTERNET hConnect=InternetConnect( hInternet, "gw.buaa.edu.cn", /// Host name INTERNET_DEFAULT_HTTP_PORT, "", "", INTERNET_SERVICE_HTTP, 0, 1 ); /// Create an HTTP request handle HINTERNET hRequest=HttpOpenRequest( hConnect, "POST", "/change_user_balance.php", /// Target HTTP_VERSION, "http://gw.buaa.edu.cn/", /// Referer lpszAccept, INTERNET_FLAG_DONT_CACHE, 1 ); /// Send the request created above BOOL bRequest=HttpSendRequest( hRequest, lpszHeader, lstrlen(lpszHeader), const_cast<char*>(lpPostData.c_str()), lstrlen(lpPostData.c_str()) ); /// Error handler if(!bRequest) { DWORD dwError=GetLastError(); cout<<"Request sent error: "<<dwError<<endl; return dwError; } string strRequest; char lpBuffer[1024]; DWORD dwByteRead=0; ZeroMemory(lpBuffer,sizeof(lpBuffer)); /// Read data while( InternetReadFile( hRequest, lpBuffer, sizeof(lpBuffer), /// Number of bytes to be read &dwByteRead /// Number of bytes which were read ) &&dwByteRead>0 ) { lpBuffer[dwByteRead]='\0'; strRequest.append(lpBuffer); ZeroMemory(lpBuffer,sizeof(lpBuffer)); } /// Close Internet handle InternetCloseHandle(hRequest); InternetCloseHandle(hConnect); InternetCloseHandle(hInternet); cout<<"Succeeded!"<<endl<<"("<<strRequest<<")"<<endl; return 0;}
0 0
- UnOnline.cpp
- cpp
- CPP
- CPP
- cpp
- cpp
- CPP
- CPP
- ClientSockThread.cpp&&ClientUrlThread.cpp
- cpp调用其他cpp
- ex34a.cpp&&ex34aDoc.cpp&&ex34aView.cpp
- MainFrm.cpp&&ServerThread.cpp&&SheetConfig.cpp
- CPP thread
- cpp->html
- CFaderWnd.cpp
- PasswordReminder.cpp
- object.cpp
- CmdTarget.cpp
- (总结)CentOS Linux搭建SVN Server配置详解
- SNMP学习之Snmp4j
- Maven与Ant比较
- Struts2不扫描jar包中的action
- contendprovider
- UnOnline.cpp
- JS Selectors API
- 作为一个程序员,不能拒绝学习
- Android ViewPager循环左右自动滑动加载Page
- 常用控件之 滚动条控件Scroll Bar
- sublime text插件开发
- C语言的星光历程
- Netty系列之Netty线程模型
- 学习笔记-JAVA-1