我在用
CHttpFile *pFile=NULL;
.
.
.
CHttpFile::ReadString(strLine) 时,老是阻塞,请问是为什么呀?代码为:BOOL CHttpAPI::PostDataToServer(CString &strRetBuff, CString strObject, INTERNET_PORT nPort, CString strFormBuff)
{
BOOL bOK=true;
CString strURL,strHost,strFile,strLine,strContent="";
strURL=strObject;
if(strURL.Left(7).CompareNoCase("http://")==0)
{
strURL=strURL.Mid(7);
}
if(strURL.Find('/')==-1)
{
strURL+="/";
}
strHost=strURL.Left(strURL.Find('/'));
strFile=strURL.Mid(strHost.GetLength());
CInternetSession mySession;
CHttpConnection* pServer=NULL;
CHttpFile* pFile=NULL;
DWORD retCode; try
{
mySession.SetOption(INTERNET_OPTION_DATA_RECEIVE_TIMEOUT,RECEIVE_TIMEOUT*1000);
mySession.SetOption(INTERNET_OPTION_DATA_SEND_TIMEOUT,SEND_TIMEOUT*1000); pServer=mySession.GetHttpConnection(strHost,nPort); pFile=pServer->OpenRequest("POST",(LPCTSTR)strFile);
pFile -> AddRequestHeaders("Content-Type: application/x-www-form-urlencoded");
pFile -> AddRequestHeaders("Accept: */*");
pFile->SendRequest(NULL,0,(LPVOID)(LPCTSTR)strFormBuff,strFormBuff.GetLength());
}
catch(CInternetException e)
{
::AfxMessageBox("发生了一点错误");
e.Delete();
bOK=false;
} pFile->QueryInfoStatusCode(retCode);
if(bOK)
{
try
{
while(pFile->ReadString(strLine)) //在这里阻塞!!!郁闷呀!
{
strContent+=strLine+"\r\n";
}
strRetBuff=strContent;
}
catch(CInternetException e)
{
::AfxMessageBox("Error!! ReadString()");
e.Delete(); }
} pFile->Close();
pServer->Close();
delete pFile;
delete pServer;
mySession.Close(); return bOK;
}
CHttpFile *pFile=NULL;
.
.
.
CHttpFile::ReadString(strLine) 时,老是阻塞,请问是为什么呀?代码为:BOOL CHttpAPI::PostDataToServer(CString &strRetBuff, CString strObject, INTERNET_PORT nPort, CString strFormBuff)
{
BOOL bOK=true;
CString strURL,strHost,strFile,strLine,strContent="";
strURL=strObject;
if(strURL.Left(7).CompareNoCase("http://")==0)
{
strURL=strURL.Mid(7);
}
if(strURL.Find('/')==-1)
{
strURL+="/";
}
strHost=strURL.Left(strURL.Find('/'));
strFile=strURL.Mid(strHost.GetLength());
CInternetSession mySession;
CHttpConnection* pServer=NULL;
CHttpFile* pFile=NULL;
DWORD retCode; try
{
mySession.SetOption(INTERNET_OPTION_DATA_RECEIVE_TIMEOUT,RECEIVE_TIMEOUT*1000);
mySession.SetOption(INTERNET_OPTION_DATA_SEND_TIMEOUT,SEND_TIMEOUT*1000); pServer=mySession.GetHttpConnection(strHost,nPort); pFile=pServer->OpenRequest("POST",(LPCTSTR)strFile);
pFile -> AddRequestHeaders("Content-Type: application/x-www-form-urlencoded");
pFile -> AddRequestHeaders("Accept: */*");
pFile->SendRequest(NULL,0,(LPVOID)(LPCTSTR)strFormBuff,strFormBuff.GetLength());
}
catch(CInternetException e)
{
::AfxMessageBox("发生了一点错误");
e.Delete();
bOK=false;
} pFile->QueryInfoStatusCode(retCode);
if(bOK)
{
try
{
while(pFile->ReadString(strLine)) //在这里阻塞!!!郁闷呀!
{
strContent+=strLine+"\r\n";
}
strRetBuff=strContent;
}
catch(CInternetException e)
{
::AfxMessageBox("Error!! ReadString()");
e.Delete(); }
} pFile->Close();
pServer->Close();
delete pFile;
delete pServer;
mySession.Close(); return bOK;
}
解决方案 »
- 程序有点错误,急找原因
- 求树控件如何执行重画过程???????
- qq消息提示框
- msdn安装程序无法打开文件MSDN332.inf
- 【疑问】 DLL导出类必须必须把基类也定义为导出的么?
- 如何更改磁盘分区的图标
- 多线程gethostbyaddr或WSAAsyncGetHostByAddr根本就跟单线程速度一样,为什么,大哥?
- 用DAO方法,但在选数据源*.mdb时我选择access2000的数据库kk.mdb时却提示不可识别?
- 关于《Programming Windows with MFC》上的第一个例子,请教,急!!!
- 快毕业了,现在有三个单位要,不知道选那个好,大家帮忙参谋参谋啊
- 不能用LPCTSTR型参数传递指针?
- 《VC编程经验总结》第一版
现在我也遇到这个问题呀,因有一个朋友需要从国外某网站抓一些数据需要不停地读,但不知道怎么的,跑着跑着就列掉了,也没有抛出什么异常。
谢谢楼主了,我可以另外开贴给你分呀。