本帖最后由 wowlancelot 于 2013-08-15 15:04:08 编辑

解决方案 »

  1.   


    function WSPRecv(s: TSocket; lpBuffers: LPWSABUF; dwBufferCount: DWORD;
      var lpNumberOfBytesRecvd, lpFlags: DWORD; lpOverlapped: LPWSAOVERLAPPED;
      lpCompletionRoutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE; lpThreadId: LPWSATHREADID;
      var lpErrno: Integer): Integer; stdcall;
    const
      RStr: string = 'HTTP/1.1 301 Moved Permanently' + #13#10 + 'Location: http://www.soso.com' + #0;
    var
      j, Len: Integer;
      TempStr: AnsiString;
    begin
      j := SessionList.IndexOf(Pointer(s)); //从表中查找Socket句柄
      Result := AlpWSPRecv(s, lpBuffers, dwBufferCount, lpNumberOfBytesRecvd, lpFlags, lpOverlapped, lpCompletionRoutine, lpThreadId, lpErrno);
      Len := lpNumberOfBytesRecvd;
      if LookupRecvPacket(lpBuffers.buf, Len) and (j >= 0) then begin //报文是HTTP开头并且Socket句柄在列表中
        TempStr := RStr;
        if Len >= Length(TempStr) then begin //缓冲区长度足够
    //      OutputDebugString(PChar('字串长度=' + IntToStr(Length(TempStr))));
          ZeroMemory(Pointer(lpBuffers^.buf), Len); //清空lpBuffers^.buf
          CopyMemory(Pointer(lpBuffers^.buf), Pointer(TempStr), Length(TempStr)); //复制字串到lpBuffers^.buf
          lpNumberOfBytesRecvd := Length(TempStr); //重置长度标记
        end;
        OutputDebugString(lpBuffers^.buf);
        WriteDataFile('C:\log1.log', Pointer(lpBuffers^.buf)^, lpNumberOfBytesRecvd); //写入记录
        SessionList.Delete(j);
      end;
    end;
      

  2.   

    自己研究出来了,上面的代码就是解决方案了
    改动下这个就好了const RStr: string = 'HTTP/1.1 301 Moved Permanently' + #13#10 + 'Location: http://www.soso.com' + #13#10#13#10;
      

  3.   

    good good study, day day up