vc http post传参提交时间:2022-06-26 21:09:12// sdfolkwlsdfs.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <string> #include <stdio.h> #include <windows.h> #include "Wininet.h" using namespace std; #pragma comment(lib,"Wininet.lib") //模拟浏览器发送HTTP请求函数 BOOL HttpRequest(char * lpHostName,short sPort,char * lpUrl,char * lpMethod,char * lpPostData,int nPostDataLen) { HINTERNET hInternet = NULL, hConnect = NULL, hRequest = NULL; BOOL bRet; string strResponse; hInternet = InternetOpen("User-Agent",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0); if(!hInternet) { return FALSE; } hConnect = InternetConnect(hInternet,lpHostName,sPort,NULL,"HTTP/1.1",INTERNET_SERVICE_HTTP,0,0); if(!hConnect) { InternetCloseHandle(hInternet); return FALSE; } hRequest = HttpOpenRequest(hConnect,lpMethod,lpUrl,"HTTP/1.1",NULL,NULL,INTERNET_FLAG_RELOAD,0); if(!hRequest) { InternetCloseHandle(hConnect); InternetCloseHandle(hInternet); return FALSE; } bRet = HttpSendRequest(hRequest,NULL,0,lpPostData,nPostDataLen); InternetCloseHandle(hRequest); InternetCloseHandle(hConnect); InternetCloseHandle(hInternet); return TRUE; } //比如要提交一个http://www.baidu.com/post.asp?id=xxx&ip=jjyy void main() { BOOL nRet = HttpRequest("www.baidu.com",80,/ "/post.asp?id=xxx&ip=jjyy",/ "POST",/ NULL,/ NULL); }