客户端代码如下:
- C/C++ code
TCHAR* szHeaders = _T("Content-Type: application/x-www-form-urlencoded");TCHAR* szFormDate = _T("p=John\r\n");DWORD dw;INTERNET_PORT nPort = 2352;CInternetSession session;CHttpConnection* pConnection = session.GetHttpConnection(_T("localhost"),nPort);dw= GetLastError();CHttpFile* pFile = NULL;pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST, _T("/Update/Update.aspx"));dw= GetLastError(); // dw = 122BOOL result = pFile->SendRequest( szHeaders, (DWORD)wcslen(szHeaders), (LPVOID)szFormDate, (DWORD)wcslen(szFormDate));pFile->QueryInfoStatusCode(dw); // dw=200 char szServerMsg[10240];DWORD dwFileSize = 0; UINT nSize = pFile->Read(szServerMsg, 1024); while (nSize > 0) { dwFileSize += nSize; nSize = pFile->Read(szServerMsg + nSize, 1024); } szServerMsg[dwFileSize] = '\0';
//szServerMsg 中返回
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>
Update Page
</title></head>
<body>
<form name="form1" method="post" action="Update.aspx" id="form1">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJNTExNDk4MTQ4ZGScs0hENO9Ms4muXBD1j2nn/FyT+A==" />
<div>
<hr />
<input type="submit" name="Button_Get" value="GET" id="Button_Get" /><br />
<table id="Table_File" rules="all" border="1" height="73" width="149">
</table>
<br />
<span id="Label_FileCount"><font face="Tahoma" size="2"></font></span><br />
</div>
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgLula3NCwLVyryJCGowUVe1rv9Pa6Pf2P/wVVRvgNCd" /></form>
</body>
</html>
服务器端代码:
- C# code
protected void Page_Load(object sender, EventArgs e) { Response.Write(Request.Form["p"]); Response.Write(Request.QueryString["g"]); }
到底是为什么!!!???
------解决方案--------------------------------------------------------
再就是OpenRequest第一个参数可以是字符串,不知道用“POST”做参数可不可以,以前弄SOAP协议没有成功,就改用.net做了。
CHttpFile* OpenRequest( LPCTSTR pstrVerb, LPCTSTR pstrObjectName, LPCTSTR pstrReferer = NULL, DWORD dwContext = 1, LPCTSTR* pstrAcceptTypes = NULL, LPCTSTR pstrVersion = NULL, DWORD dwFlags = INTERNET_FLAG_EXISTING_CONNECT );
CHttpFile* OpenRequest( int nVerb, LPCTSTR pstrObjectName, LPCTSTR pstrReferer = NULL, DWORD dwContext = 1, LPCTSTR* pstrAcceptTypes = NULL, LPCTSTR pstrVersion = NULL, DWORD dwFlags = INTERNET_FLAG_EXISTING_CONNECT );