请参见我的上一个帖子http://community.csdn.net/Expert/topic/3839/3839571.xml?temp=.1526148,我测试了一下,的确可以了,但今天一测试,发现连接保持时间只有10秒,有没有办法让连接保持住,加了Keep-Alive也不行,我的请求类似如下
POST /Request.htm HTTP/1.1
Host: 127.0.0.1
Accept: */*
Connection: keep-alive
Content-Type: multipart/form-data
Content-Length: 100
100字节数据
服务器响应类似这样是
HTTP/1.1 200 OK
Date: Tue, 21 May 2002 12:34:56 GMT
Server: Microsoft-IIS/6.0
Connection: keep-alive
Last-Modified: Fri, 12 Nov 2004 02:56:20 GMT
Content-Type: application/zip
Content-Length: 100
100字节数据

解决方案 »

  1.   

    把Content-Length: 100改成 Content-Length: 999999999999999999999999999999
    哈哈。
      

  2.   

    包发出去,收到403 The ISA Server denies the specified Uniform Resource Locator,这个应该是微软这个ISA配置上的问题吧,或者客户端自己的配置问题,哪位精通ISA的来解决一下
      

  3.   

    我写过一个很简单的代理,专门处理我自己的Get和Post请求,现在是每10秒左右连接一次,运行几个月,不成问题,不知道大家如何改进。
    在Server有Connect请求时,开辟线程StartClient。
    代码如下:
    void StartClient(void* pParam)
    {
    int iResult;
    char strBuffer[20000];
    CString tmpStr,SecondStr;
    long pos1,pos2;
    bool FindHost=false,FindBoundary = false,RecFinished=false;//,FindConnection=false;
    // bool recFirst=true;
        
    CString Host,boundary;
    int Port=80; FD_SET localset,acceptset;;
    timeval tv; struct sockaddr_in ClientAddr;
    struct  sockaddr_in addr;
    SOCKET localsocket;
    SOCKET ClientSocket = SOCKET_ERROR;
    unsigned long ul = 0;
    int timedout = 30000;

    CString ClientIP;
    int len;
    len = sizeof(struct sockaddr_in); ClientAddr.sin_family=AF_INET;
    ClientSocket=accept(Server,(sockaddr*)&ClientAddr,&len);  //注意,Server是全局变量
    if(ClientSocket==SOCKET_ERROR||paused)
    {
       goto End;
    } localsocket = socket(AF_INET,SOCK_STREAM,0);
    if(localsocket==INVALID_SOCKET||paused) 
    {
    goto End;
    } //Set non-blocking 
    if(ioctlsocket(localsocket, FIONBIO, (unsigned long*)&ul)==SOCKET_ERROR||paused)
    {
    goto End;
    } //Check Client IP
    ClientIP = (CString)inet_ntoa(ClientAddr.sin_addr);
    if(ClientIP.Find("192.168.")==-1&&ClientIP!="127.0.0.1"||paused)
    {
       goto End;
    } //Receive Parameters
             tmpStr = "";
    do
    {
    strset(strBuffer,'\0');
    //select检测rec超时(30s)
    FD_ZERO(&acceptset); 
    FD_SET(ClientSocket,&acceptset); 
    tv.tv_sec=60;
    tv.tv_usec=0;
    if (select(0,&acceptset,0,0,&tv)<=0||paused)
    {
                             goto End;
    }
    iResult=recv(ClientSocket,strBuffer,sizeof(strBuffer),0);
    CFile myfile;
    try
    {
    myfile.Open("log.ini",CFile::modeWrite|CFile::modeCreate|CFile::shareDenyNone);
    myfile.SeekToEnd();
    myfile.Write(strBuffer,iResult);
    myfile.Close();
    }
    catch(...)
    {
    myfile.Close();
    }
    if(iResult==SOCKET_ERROR||paused)
    {
       goto End;
    } if(SecondStr.GetLength()<=40)
    SecondStr=SecondStr+strBuffer;
    else
    SecondStr=SecondStr.Right(SecondStr.GetLength()-(int)strlen(strBuffer))+strBuffer; //if(!FindHost&&!FindBoundary&&!FindConnection)
    if(!FindHost||!FindBoundary)//||!FindConnection)
    {
    tmpStr = tmpStr+strBuffer;
    if(tmpStr.Left(1)=="G") FindBoundary = true; if(!FindHost)
    {
    pos1 = tmpStr.Find("Host:")+6;
    if(pos1>=6)
    {
    pos2=tmpStr.Find("\r\n",pos1);
    if(pos2>0)
    {
    FindHost = true;
    Host = tmpStr.Mid(pos1,pos2-pos1).Trim().MakeUpper();
    if(Host.Find(":")>=0)
    {
    Port = atoi(Host.Right(Host.GetLength()-Host.Find(":")-1).Trim());
    if(Port==0) Port = 80;
    Host = Host.Left(Host.Find(":")).Trim().MakeUpper();
    if(Host=="")
    goto End;
    }
    if(!GeneralHost.IsEmpty()) 
    {
    Host = GeneralHost;
    Port = ListenPort;
    }
    //Send the tmpStr to Host:Port
    addr.sin_family=AF_INET;
    addr.sin_port=htons(Port);
    //Get Host by Name,or by IP
    if(Host.FindOneOf("ABCDEFGHIJKLMNOPQRSTUVWXYZ")>=0)
    {
    hostent *host;
    host = gethostbyname(Host);
    if(host==NULL||paused) 
    {
    goto End;
    }
    memcpy(&(addr.sin_addr),host->h_addr,host->h_length);
    }
    else
    {
    addr.sin_addr.s_addr=inet_addr(Host);
    }
    //设置连接超时,10 Seconds
    if((::setsockopt(localsocket,SOL_SOCKET,SO_SNDTIMEO,(char *)&timedout,sizeof(timedout))==SOCKET_ERROR)||paused)
    {
    goto End;
    }
    }
    }
    else //not found "Host:"
    {
    if(tmpStr.GetLength()>40000||paused)
    goto End;
    }
    }
    if(!FindBoundary)
    {
    pos1 = tmpStr.Find("boundary=")+9;
    if(pos1>=9)
    {
    pos2=tmpStr.Find("\r\n",pos1);
    if(pos2>0)
    {
    FindBoundary = true;
    boundary = tmpStr.Mid(pos1,pos2-pos1).Trim();
    }
    else //not found "\r\n"
    {
    if(tmpStr.GetLength()>40000||paused)
    goto End;
    }
    }
    else //not found "boundary="
    {
    if(tmpStr.GetLength()>40000||paused)
    goto End;
    }
    }

    /*
    if(!FindConnection)
    {
    pos1 = tmpStr.Find("Proxy-Connection: Keep-Alive\r\n");
    if(pos1>=0)
    {
    FindConnection = true;
    tmpStr.Replace("Proxy-Connection: Keep-Alive","Connection: close");
    }
    else //not found "Proxy-Connection"
    {
    if(tmpStr.GetLength()>40000||paused)
    goto End;
    }
    }
    */

    if(FindHost&&FindBoundary)//&&FindConnection)
    {
    if(connect(localsocket,(struct sockaddr*)&addr,sizeof(addr))!=0||paused)
    {
    goto End;
    }
    iResult=send(localsocket,tmpStr,iResult,0);
    if(iResult==SOCKET_ERROR||paused)
    {
    goto End;
    }
    }
    }
    else   //FindHost = true  FindBoundary = true  FindConnection = true
    {
    FD_ZERO(&localset); 
    FD_SET(localsocket,&localset); 
    tv.tv_sec=60;
    tv.tv_usec=0;
    if(select(0,NULL,&localset,NULL,&tv)<=0||paused)
    {
    goto End;
    }
    iResult=send(localsocket,strBuffer,iResult,0);
    if(iResult==SOCKET_ERROR||paused)
    {
    goto End;
    }
    } if((tmpStr.Left(1)=="G")&&(SecondStr.Right(4)=="\r\n\r\n"))
    RecFinished = true;
    if((tmpStr.Left(1)=="P")&&(SecondStr.Find("--"+boundary+"--\r\n")!=-1))
    RecFinished = true;
    }
    while(iResult!=0&&iResult!=SOCKET_ERROR&&!RecFinished&&!paused); if(iResult==SOCKET_ERROR||paused)
    goto End; //Receive from Web
    do
    {
    strset(strBuffer,'\0');
    //select检测rec超时(30s)
    FD_ZERO(&localset); 
    FD_SET(localsocket,&localset); 
    tv.tv_sec=300;
    tv.tv_usec=0;
    if (select(0,&localset,0,0,&tv)<=0||paused)
    {
                goto End;
    }
    iResult=recv(localsocket,strBuffer,sizeof(strBuffer),0);
    if(iResult==SOCKET_ERROR||paused)
    {
       goto End;
    } FD_ZERO(&acceptset); 
    FD_SET(ClientSocket,&acceptset); 
    tv.tv_sec=300;
    tv.tv_usec=0;
    if(select(0,NULL,&acceptset,NULL,&tv)<=0||paused)
    {
    goto End;
    }
    iResult=send(ClientSocket,strBuffer,iResult,0);
    if(iResult==SOCKET_ERROR||paused)
    {
    goto End;
    } }
    while(iResult!=0&&iResult!=SOCKET_ERROR&&!paused); //Exit the Thread
        End:
    //wait for the last send operation over
    FD_ZERO(&acceptset); 
    FD_SET(ClientSocket,&acceptset); 
    tv.tv_sec=120;
    tv.tv_usec=0;
    select(0,NULL,&acceptset,NULL,&tv); closesocket(localsocket);
    closesocket(ClientSocket); _endthread();
    }
      

  4.   

    塑造一些怪异的包是可能让服务器挂的。
    试一下用Get的方法,总不让最后的\r\n\r\n出现,然后自己用循环塑造一些Get的地址,也就是每次循环只发一部分过去,隔一秒发下一截。
      

  5.   

    到专门的ISA网站上去找,说"403 The ISA Server denies the specified Uniform Resource Locator"应该是微软这个ISA配置上的问题吧,或者客户端自己的配置问题。另外,我觉得很奇怪,为什么有的网站用IP反倒上不去,提示404或者403,抓包看后唯一的区别就是Host: 后面的内容,一个带IP,一个为域名,IP那个就不行,奇怪死了,也不晓得这些鬼包是不是目标主机返回来的,因为你调用connect后,并不一定就连上了真正目标主机,而是只连上了出口的网关或代理
      

  6.   

    激活包和UDP的原理一样,就是发送一个随便内容的小包,让服务器知道这个通道有在通信。
    有可能是ISA服务器认为该TCP连接有十秒没有发送数据,链路已断了.
      

  7.   

    Http Proxy 也封了吗,如果没封Http Proxy 有Get 和Connect两种方式,后者你想干什么都行,所以有所谓的通过HTTP运行XX软件之说.
    如果封了估计你可以和服务端保持两个Connection ,这样一个用来发包,一个用来收包,发包可以用选项类的HTTP头,另外这些数据可以用BASE64编码;收包嘛就无所谓了,还有好象Content-Length是可以不写的,动态生成(CGI)的很多是没有这个头的,所以两个都可以保持