运行时服务器检测不到POST方法发送的变量,请看看什么原因?
    客户端程序如下:
void xx(void)
{
CHAR szReceiveBuffer[36000];
memset(szReceiveBuffer,0,36000);
char *req="POST HTTP/1.0\r\n"
"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, */*\r\n"
"Accept-Language: en-us\r\n"
"Accept-Encoding: gzip, deflate\r\n"
"User-Agent: Mozilla/4.0\r\n"
"Content-Length: 34\r\n"
"Host: 127.0.0.1\r\n"
"Content-Type: application/x-www-form-urlencoded\r\n\r\n";

LPSTR lpOptions="user=admin&Pwd=admin&submit=提交"; CInternetSession cInternetSession;
CHttpConnection * pHttpConnection = cInternetSession.GetHttpConnection(_T("127.0.0.1"), (INTERNET_PORT)80);
CHttpFile * pHttpFile = pHttpConnection->OpenRequest("POST", _T("/admin/test.asp"));
pHttpFile->AddRequestHeaders(req);
pHttpFile->SendRequest(0,0, (LPVOID) lpOptions, (DWORD)strlen(lpOptions));
pHttpFile->Read(szReceiveBuffer, 36000);
cInternetSession.Close();
//CString hh=szReceiveBuffer;
//if(hh.Find("您输入了错误的帐号或",0))
        MessageBox(szReceiveBuffer); return ;
}服务器端的ASP文件内容如下:
<%=request.form("user")%>

解决方案 »

  1.   

    好像不是这样做的
    看看这个
    http://expert.csdn.net/Expert/topic/1881/1881667.xml?temp=.734112
      

  2.   

    char *req="POST HTTP/1.0\r\n"
    "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, */*\r\n"
    "Accept-Language: en-us\r\n"
    "Accept-Encoding: gzip, deflate\r\n"
    "User-Agent: Mozilla/4.0\r\n"
    "Content-Length: 34\r\n"
    "Host: 127.0.0.1\r\n"
    "Content-Type: application/x-www-form-urlencoded\r\n\r\n";

    LPSTR lpOptions="user=admin&Pwd=admin&submit=提交";
    本身这个HTTP请求头就有问题,Post 后面要有一个URL地址,如果网站主目录,可以使用 post / http 1.1 其中/不可或缺
    附加数据指出是34个字节,但是“user=admin&Pwd=admin&submit=提交”好像应该是32个字节。回车符和换行符不应包含在内。
        建议楼主在调试http请求时,先制作一个网页,再打开microsoft提供的application test容器,录制测试文本,得到发送的请求包,或者使用http跟踪工具,把浏览器向远程提交的http请求包截获过来,然后按照录制的结果使用各种发送方法发送请求。
      

  3.   

    同时也利用这些跟踪工具跟踪一下你制作的客户端程序,比较两个包看那些部分不一样。你可以分析一下,Wininet API函数是否会自动向请求头结束部分添加\r\n
    如果是这样的话http请求头中
    Content-Type: application/x-www-form-urlencoded\r\n\r\n";
    就可能多了一个\r\n
      

  4.   

    推荐使用http协议跟踪工具工具EffeTech HTTPSniffer