void post() { CInternetSession session("My Session"); CHttpConnection* pServer = NULL; CHttpFile* pFile = NULL; CString ServerName = "webmail.21cn.com"; INTERNET_PORT nPort = 80; DWORD retcode; char outBuff[300] = "LoginName=aaa&passwd=xxx&DomainName=21cn.com";//I have test this with my loginname and password try { pServer = session.GetHttpConnection(ServerName,nPort); pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,"/NULL/NULL/NULL/NULL/NULL/SignIn.gen",NULL,1,NULL,NULL,INTERNET_FLAG_EXISTING_CONNECT); pFile -> AddRequestHeaders("Content-Type: application/x-www-form-urlencoded"); pFile -> AddRequestHeaders("Accept: */*"); pFile -> SendRequest(NULL,0,outBuff,strlen(outBuff)+1); pFile -> QueryInfoStatusCode(retcode); // you can read from the file after this......I've just left it out. for(int i=0;i<10;i++)//read ten line of returned HTML,you need to edit this to use the result { CString smsg; pFile->ReadString(smsg); AfxMessageBox(smsg); } DWORD dwlen=pFile->GetLength(); char buf[1024]; DWORD dwread=pFile->Read(buf,1024); } catch (CInternetException * e){}; delete pFile; delete pServer; session.Close(); }
{
CInternetSession session("My Session");
CHttpConnection* pServer = NULL;
CHttpFile* pFile = NULL;
CString ServerName = "webmail.21cn.com";
INTERNET_PORT nPort = 80;
DWORD retcode;
char outBuff[300] = "LoginName=aaa&passwd=xxx&DomainName=21cn.com";//I have test this with my loginname and password
try
{
pServer = session.GetHttpConnection(ServerName,nPort);
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,"/NULL/NULL/NULL/NULL/NULL/SignIn.gen",NULL,1,NULL,NULL,INTERNET_FLAG_EXISTING_CONNECT);
pFile -> AddRequestHeaders("Content-Type: application/x-www-form-urlencoded");
pFile -> AddRequestHeaders("Accept: */*");
pFile -> SendRequest(NULL,0,outBuff,strlen(outBuff)+1);
pFile -> QueryInfoStatusCode(retcode);
// you can read from the file after this......I've just left it out.
for(int i=0;i<10;i++)//read ten line of returned HTML,you need to edit this to use the result
{
CString smsg;
pFile->ReadString(smsg);
AfxMessageBox(smsg);
}
DWORD dwlen=pFile->GetLength();
char buf[1024];
DWORD dwread=pFile->Read(buf,1024);
}
catch (CInternetException * e){};
delete pFile;
delete pServer;
session.Close();
}