我是初学者高手帮个忙

0738111080 2006-04-20 08:50:41
我在编译是有语法错误,高手帮我看看问题在那里!!!
BOOL CHttpServer::ProcessRequest(string szRequest,string &szRespons,BOOL &bkeepAlive)
{
string szMethod;
string szFileName;
string szFullpathName;
string szFileExt;
string szStatusCode("200 ok");//szContenType
string szContentType("text/html");
string szConnectionType("close");
string szNotFoundMessage;
string szDateTime;
string pResponseHeader[2048];
fpos_t lengthActual=0,length=0;
char *pBuf=NULL;
int n=0;
//check Method
n=szRequest.find(" ",0);
if(n!=string::npos)
{
szMethod=szRequest.substr(0,n);
if(szMethod=="GET")
{
//GET FILE NAME
int n1=szRequest.find(" ",n+1);
if(n1!=string::npos)
{
szFileName=szRequest.substr(n+1,n1-n-1);
// do some check
n1=szFileName.find("..",0);
if(n1!=string::npos)
{
szStatusCode="404 Resource not found";
szFileName=ERROR404;
}
if(szFileName=="/")
szFileName=string(g_pSvrOPtions->m_SZDefaultpage);
}
else
{
szStatusCode="501 not implemented";
szFileName=ERROR501;
}
}
else
{
szStatusCode="501 not implemented";
szFileName=ERROR501;
}
}

//Determine connectin type
n=szRequest.find("\nConnection:Keep-Alive",0);
if(n!=string::npos)
bkeepAlive=TRUE;
else
bkeepAlive=FALSE;
//Figure out content type
int nPointPos=szFileName.rfind(".");
if(nPointPos!=string::npos)
{
szFileExt=szFileName.substr(nPointPos+1,szFileName.size());
strlwr((char*)szFileExt.c_str());
MIMETYPES::iterator it;
it=m_MimeTYpes.find(szFileExt);
if(it!=m_MimeTYpes.end())
szContentType=(*it).second;
}

//obtain current GMT date/time
char szDT[128];
struct tm *newtime;
long ltime;
time(<ime);
newtime=gmtime(<ime);
strftime(szDT,128,"%a %d %b %y %H:%M:%S GMT",newtime);

// Read the file
FILE *f;
szFullpathName=string(g_pSvrOPtions->m_szHomeDir)+"\\"+szFileName;
f=fopen(szFullpathName.c_str(),"r+b");
if(f!=NULL)
{
fseek(f,0,SEEK_END);
fgetpos(f,&lengthActual);
fseek(f,0,SEEK_SET);

pBuf=new char[lengthActual+1];
length=fread(pBuf,1,lengthActual,f);
fclose(f);

//make response
//这行有错语
sprintf(pResponseHeader, "HTTP/1.0 %s\r\nDate:%s\r\nServer: %s\r\
nAccept-Ranges: bytes\r\nContent-length: %d\r\nConnection:%s\r\
nContent-Type:%s\r\n\r\n",
szStatusCode.c_str(),szDT,WEBSERVER_NAME,(int)length,
bkeepAlive? "Keep-Alive": "close" ,szContentType.c_str());
}
else
{
//in case of file found
szFullpathName=g_pSvrOPtions->m_szHomeDir+ERROR404;
f=fopen(szFullpathName.c_str(),"r+b");
if(f!=NULL)
{
//retrive file size
fseek(f,0,SEEK_END);
fgetpos(f,&lengthActual);
fseek(f,0,SEEK_SET);
pBuf=new char[lengthActual+1];
length=fread(pBuf,1,lengthActual,f);
fclose(f);
szNotFoundMessage=string(pBuf,length);
delete [] pBuf;
pBuf=NULL;
}
szStatusCode="404 resource not found ";
sprintf(pResponseHeader,"HTTP/1.0%s\r\nContent-Length:%d\r\
nContent-Type;text/html\r\nDate: %s\r\nServer:%s\r\n\r%s",
szStatusCode.c_str(),szNotFoundMessage.size(),szDT,WEBSERVER_NAME,
szNotFoundMessage.c_str());
bkeepAlive=FALSE;
}
szRespons=string(pResponseHeader);
//szRespons=string(pResponseHeader);
if(pBuf)
szRespons+=string(pBuf,length);
delete [] pBuf;
pBuf=NULL;

return TRUE;





E:\libiyan\lby\MyWeb\HttpServer.cpp(302) : error C2664: 'sprintf' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > [2048]' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
...全文
86 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

18,363

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧