设为首页  
联系我们  
加入收藏  
网页制作 冲浪宝典 图形图像 操作系统 软件教学 编程开发 认证考试 安全技术 站长专区 文学驿站 娱乐天地 游戏天地 办公软件
文章搜索
您的位置: 首页 >> 文章首页 >> 编程开发 >> 其他开发语言 >> How to simulate a Form POST request by using WinInet
精品推荐
其他开发语言点击TOP10
·数字小键盘指法练习
·用C语言编通讯录程序(初学者级别的)
·Modem 常用AT指令集
·单片机模拟I2C总线及24C02(I2C EEPROM)读写实例(源代码)
·C++经典电子书下载
·Thinking in C++ 简体中文第二版
·debug和release的区别
·error LNK2001: unresolved external symbol __ftol2 错误解决
·C库函数手册
·一个简单的C语言编译器
编程开发点击TOP10
·数字小键盘指法练习
·ASP.NET 程序中常用的三十三种代码
·用C语言编通讯录程序(初学者级别的)
·我写的Java学生成绩管理系统源代码
·CHK文件恢复工具
·Modem 常用AT指令集
·java笔试题
·异常java.sql.SQLException: Io exception:The Network Adapter could not establish connection
·单片机模拟I2C总线及24C02(I2C EEPROM)读写实例(源代码)
·C++经典电子书下载
精选专题

How to simulate a Form POST request by using WinInet

作者: 来源:网络文章 时间:2005-12-17 0:40:27

This article was previously published under Q165298
On this Page
SUMMARYCS/downArrow.gif" align=middle>SUMMARY
MORE INFORMATIONMORE INFORMATION
REFERENCESREFERENCES

SUMMARY

To properly simulate a Form submission using WinInet, you need to send a header that indicates the proper Content-Type. For Forms, the proper Content-Type header is:
Content-Type: application/x-www-form-urlencoded

MORE INFORMATION

In many cases, the server does not respond appropriately if a Content-Type is not specified. For example, the Active Server Pages component of IIS 3.0 actually checks this header specifically for 'application/x-www-form- urlencoded' before adding form variables to the "Request.Form" object. This MIME/Content-Type indicates that the data of the request is a list of URL- encoded form variables. URL-encoding means that space character (ASCII 32) is encoded as '+', special character sUCh '!' encoded in hexadecimal form as '%21'.

Here is a snippet of code that uses the MFC WinInet classes to simulate a Form POST request:
CString strHeaders =_T("Content-Type: application/x-www-form-urlencoded");// URL-encoded form variables -// name = "John Doe", userid = "hithere", other = "P&Q"CString strFormData = _T("name=John+Doe&userid=hithere&other=P%26Q");CInternetSession session;CHttpConnection* pConnection =session.GetHttpConnection(_T("ServerNameHere"));CHttpFile* pFile =pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST,_T("FormActionHere"));BOOL result = pFile->SendRequest(strHeaders,(LPVOID)(LPCTSTR)strFormData, strFormData.GetLength());
Without MFC, the same code translates to straight SDK calls as follows:
static TCHAR hdrs[] =_T("Content-Type: application/x-www-form-urlencoded");static TCHAR frmdata[] =_T("name=John+Doe&userid=hithere&other=P%26Q");static LPSTR accept[2]={"*/*", NULL};// for clarity, error-checking has been removedHINTERNET hSession = InternetOpen("MyAgent",INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);HINTERNET hConnect = InternetConnect(hSession, _T("ServerNameHere"),INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);HINTERNET hRequest = HttpOpenRequest(hConnect, "POST",_T("FormActionHere"), NULL, NULL, accept, 0, 1);HttpSendRequest(hRequest, hdrs, strlen(hdrs), frmdata, strlen(frmdata));// close any valid internet-handles

REFERENCES

For more information about URL-encoding and the format of a Form POST request, see section 8.2 in RFC 1866.

How to simulate a Form POST request by using WinInet 相关文章:
How to simulate a Form POST request by using WinInet 相关软件:
特别声明:本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
转载请注明来源:http://www.xgdown.com