c++实现httppost请求

c++实现httppost请求

ID:25428913

大小:49.10 KB

页数:5页

时间:2018-11-20

c++实现httppost请求_第1页
c++实现httppost请求_第2页
c++实现httppost请求_第3页
c++实现httppost请求_第4页
c++实现httppost请求_第5页
资源描述:

《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_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/

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。