VC模拟POST提交
来源:互联网 发布:单片机项目私活 编辑:程序博客网 时间:2024/05/17 09:07
VC模拟POST提交
源码(部分注释我已经删掉了,还是很容易看懂的):
#include "stdafx.h"#include <stdio.h>#include <afxinet.h>/***模拟POST提交*///////////////////////////////////////////////////////////////////////////void main(){CString strHost = _T("127.0.0.1");CString strUrl = _T("/action.asp");INTERNET_PORT m_Port = 80;CInternetSession m_Session(_T("HttpClient"));CHttpConnection * m_Server = NULL;CHttpFile * m_File = NULL;CString strRequest = _T("xsxh=20104833");//提交的数据CString strHeader =_T("Content-Type: application/x-www-form-urlencoded\r\n");try{m_Server = m_Session.GetHttpConnection(strHost,m_Port);if(m_Server == NULL)printf("CHttpConnection failed!");m_File = m_Server->OpenRequest(CHttpConnection::HTTP_VERB_POST,strUrl);if (m_File == NULL)printf("CHttpFile is NULL!");m_File->AddRequestHeaders(strHeader);m_File->AddRequestHeaders(_T("Accept-Language: zh-cn"));//特别这个头的部分,如果请求包头错误,那么肯定不会成功。建议:自己网页提交时抓包m_File->AddRequestHeaders(_T("Accept-Charset:GB2312"));m_File->SendRequest(strHeader,(LPVOID)(LPCTSTR)strRequest,strRequest.GetLength());DWORD httpStatus;m_File->QueryInfoStatusCode(httpStatus);printf("httpStatus:%d\n",httpStatus);if (httpStatus == HTTP_STATUS_OK){freopen("out.htm","w",stdout);CString strLine;int m_read;while((m_read = m_File->ReadString(strLine)) > 0)printf("%s\n",strLine);fclose(stdout);}elseprintf("HTTP_STATUS_FAILED\n");}catch (CInternetException* e){printf("Error:%d\n",e->m_dwContext);}if(m_File)delete m_File;if (m_Server)delete m_Server;m_Session.Close();}//////////////////////////////////////////////////////////////////////////
stdafx.h文件代码就不贴了,随便建一个MFC工程里面都会有,贴过来就OK。
- VC模拟POST提交
- VC模拟POST提交
- php 模拟POST提交
- 模拟post提交json
- 模拟post提交文件
- curl 模拟post 提交
- 模拟post表单提交
- curl模拟post提交
- curl模拟post提交
- VC++ 模拟表单提交
- winform模拟post提交表单
- C#winform模拟post提交
- C#winform模拟post提交
- java模拟get/post提交
- php模拟post提交数据
- HTTP 模拟POST方式提交
- php模拟post提交数据
- C#模拟POST提交表单
- linux学习笔记2
- linux乱码
- 删除系统服务
- 基数排序
- UVA 575 - Skew Binary (模拟)
- VC模拟POST提交
- JAVA重载与重名
- CSS学习总结
- UVA 10250 - The Other Two Trees(几何)
- 生活随笔:看房子
- c++创建对象的两种方式
- Java命名规范。
- UVA 112 - Tree Summing(栈)
- apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for