欢迎来到天天文库
浏览记录
ID:25428913
大小:49.10 KB
页数:5页
时间:2018-11-20
《c++实现httppost请求》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、C++实现HttpPost请求参考资料:http://apps.hi.baidu.com/share/detail/39003388http://blog.csdn.net/yc0188/article/details/4741871http://bbs.chinaunix.net/thread-2094334-1-1.html//头文件#include#include#includeusingnamespacestd;//函数声明intrequest(char*hostname,char*api,char
2、*parameters);//方法调用int_tmain(intargc,TCHAR*argv[],TCHAR*envp[]){ intnRetCode=0; //initializeMFCandprintanderroronfailure if(!AfxWinInit(::GetModuleHandle(NULL),NULL,::GetCommandLine(),0)) { //TODO:changeerrorcodetosuityourneeds _tprintf(_T("FatalError:MFCinitializationfailed
3、n")); return1; } request("reg.163.com","http://reg.163.com/CheckUser.jsp","test"); returnnRetCode;}//函数实现intrequest(char*hostname,char*api,char*parameters){ WSADATAWsaData; WSAStartup(0x0101,&WsaData); //初始化socket structhostent*host_addr=gethostbyname(hostname); if(host_a
4、ddr==NULL) { cout<<"Unabletolocatehost"<h_addr_list); intsock=socket(AF_INET,SOCK_STREAM,0); if(sock==-1) { return-100; } //建立
5、连接 if(connect(sock,(conststructsockaddr*)&sin,sizeof(sockaddr_in))==-1) { cout<<"connectfailed"<6、(send_str,hostname); strcat(send_str,"r"); strcat(send_str,"Connection:keep-aliver"); charcontent_header[100]; sprintf(content_header,"Content-Length:%dr",strlen(parameters)); strcat(send_str,content_header); strcat(send_str,"Cache-Control:max-age=0r"); strcat(send_s7、tr,"Origin:http://www.hao123.comr"); strcat(send_str,"User-Agent:Mozilla/5.0(WindowsNT6.1)AppleWebKit/535.1(KHTML,likeGecko)Chrome/15.0.849.0Safari/535.1r"); strcat(send_str,"Content-Type:application/x-www-form-urlencodedr"); strcat(send_str,"Accept:text/html,application/
6、(send_str,hostname); strcat(send_str,"r"); strcat(send_str,"Connection:keep-aliver"); charcontent_header[100]; sprintf(content_header,"Content-Length:%dr",strlen(parameters)); strcat(send_str,content_header); strcat(send_str,"Cache-Control:max-age=0r"); strcat(send_s
7、tr,"Origin:http://www.hao123.comr"); strcat(send_str,"User-Agent:Mozilla/5.0(WindowsNT6.1)AppleWebKit/535.1(KHTML,likeGecko)Chrome/15.0.849.0Safari/535.1r"); strcat(send_str,"Content-Type:application/x-www-form-urlencodedr"); strcat(send_str,"Accept:text/html,application/
此文档下载收益归作者所有