yle="COLOR: #0000ff">return 0;  //正常返回
}

int FindContentLength(string header)
{
    std::transform(header.begin(),header.end(),header.begin(),(
int(*)(int)) tolower);
    
    
string::size_type pos = header.find("content-length",0);
    
if(pos != string::npos)
    
{
        
string::size_type posEnd = header.find("\r\n",pos);
        
string contentString = header.substr(pos,posEnd - pos);
        userlog(contentString.c_str());
        pos 
= contentString.find(":",0);
        
        
string strLength = contentString.substr(pos + 1);

        
return (int)std::strtol(strLength.c_str(),NULL,10);
    }

    
return 0;
}



int RecvHttpHeader(int socket, string& header)
{
    header.clear();

    
char chRecvBuf[1];
    
    
char endBytes[] = 13101310 };
    
int posCompare = 0;
    
while (true
    
{

        
int b = recv(socket,chRecvBuf,1,0);
        
if (b == -1)
            
return -1;

        header.append(chRecvBuf,
1);
        
        
if (endBytes[posCompare] == chRecvBuf[0]) 
        
{
            posCompare
++;
            
if (posCompare == sizeof(endBytes)) 
            
{
                
break;
            }

        }

        
else 
        

抱歉!评论已关闭.