64,662
社区成员
发帖
与我相关
我的任务
分享
CInternetSession m_InetSession(_T("session"),
0,
INTERNET_OPEN_TYPE_PRECONFIG,
NULL,
NULL,
INTERNET_FLAG_DONT_CACHE); //设置不缓冲
CHttpConnection* pServer = NULL;
CHttpFile* pFile = NULL;
CString strHtml = "";
CString strRequest = _T("userAccount=chenkaijia&userpassword=admini"); //POST过去的数据
CString strHeaders = _T("Content-Type: application/x-www-form-urlencoded");
try{
INTERNET_PORT nPort; //端口
nPort=80;
pServer = m_InetSession.GetHttpConnection(_T("www.wetoband.com"), nPort);
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,_T("/login"),NULL,1,NULL,_T("HTTP/1.1"),INTERNET_FLAG_RELOAD);
pFile->AddRequestHeaders(strHeaders);
pFile->SendRequestEx(strRequest.GetLength());
pFile->WriteString(strRequest);
pFile->EndRequest();
DWORD dwRet;
pFile->QueryInfoStatusCode(dwRet);
pFile->QueryInfoStatusCode(dwRet);
if(dwRet != HTTP_STATUS_OK)
{
CString errText;
errText.Format("POST出错,错误码:%d", dwRet);
AfxMessageBox(errText);
}
if (dwRet == HTTP_STATUS_OK){
// CString strLine;
CString strLine;
while ((pFile->ReadString(strLine))>0)
{
strHtml += strLine;
}
}
delete pFile;
delete pServer;
}
catch (CInternetException* e){
e->m_dwContext;
}
m_SiteInfo=strHtml; //m_SiteInfo是一个对话框关联变量,用来显示,与本程序无多大关系
UpdateData(false);
}
感觉我代码肯定哪里错误,求大神们救急啊
接收回来的信息就只有一个大括号 :{}