用delphi开发的客户程序,需要跟asp程序进行交互,请问各位高手,它们之间的数据是如何交互的?多谢,details will be appreciated

解决方案 »

  1.   

    我会delphi
    也会asp
    但是不会交互
      

  2.   

    TidHTTP 看看这个控件,D7自带的。相信你会很容易得到结果。
      

  3.   

    用httpd控件
    通过表单方式提交asp网页通过接收表单信息处理使用纯文本格式(自己定义,只要客户端能够处理这些字符串)返回客户端从返回的字符串中提取有用信息
      

  4.   

    asp
    <%
    set fso=server.createobject("scripting.filesystemobject")  
    'mainpath=server.mappath("/")
    'mainpath="E:\delphi"
    mainpath="E:\"
     %><%
    vpath="/"
    NETHDstring=""
    cmdcommand=Trim(Request.Form("command"))
    'if cmdcommand="" then cmdcommand=Trim(Request.QueryString("command"))
    if cmdcommand="" then cmdcommand="null"
    cmd=split(cmdcommand,"|",-1,1)
    cmdfull=cmd(0)
    for i=1 to UBound(cmd)
    cmdfull=cmdfull&" "&cmd(i)
    next
    '''''''''''IP
    userip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
    userip2 = Request.ServerVariables("REMOTE_ADDR")
    if userip = ""  then 
    userip=userip2
    End If 'useroption="BA464C6D"
    useroption="&HB9" mod 2
     select case trim(cmd(0))
    case "list"
    if UBound(cmd)=0 then
    'call list(physicspath("/"))
    vpath="/"
    else
    'call list(physicspath(trim(cmd(1))))
    vpath=trim(cmd(1))
    end if
    if Fso.FolderExists(physicspath(vpath)) then
    call info("命令成功完成!")
    call list(physicspath(vpath))
    else
    call info("路径不存在!")
    end if
    case "download"
    if UBound(cmd)=0 then
    vpath="/"
    else
    vpath=trim(cmd(1))
    end if
    if fso.FileExists(physicspath(vpath)) then
    call info("命令成功完成!")
    call download(physicspath(vpath))
    else
    call info("文件不存在!")
    end if
    case "login"
    call login(cmd(1),cmd(2))
    case "loginout"
    call loginout()
    case else
    call info("无此命令字!")
    end select
    call headinfo()
    NETHDstring=NETHDstring&"[end]"
    Response.Write(NETHDstring)%><% 
    function physicspath(path)
    physicspath=mainpath&replace(path,"/","\")
    end function 
    sub login(user,pass)
    session("user")=user
    session("pass")=pass
    end sub
    sub loginout()
    session("user")=""
    session("pass")=""
    end sub
    '头信息
    sub headinfo()




    '''''''''''说明文字''''''''''''''
    'Response.Write("####################################################"&VbCrLf)
    'Response.Write("###        网络硬盘服务端 V1.0.0.0            ######"&VbCrLf)
    'Response.Write("#######    tinder              #####################"&VbCrLf)
    'Response.Write("#######    [email protected]  #####################"&VbCrLf)
    'Response.Write("####################################################"&VbCrLf)
    '''''''''''''[head]'''''''''''''
    headstring=""
    headstring=headstring&"[head]"&VbCrLf
    headstring=headstring&"Server Version|V1.0.0.0"&VbCrLf
    headstring=headstring&"Server Time|"& now &VbCrLf
    headstring=headstring&"Client Version|V1.0.0.0"&VbCrLf
    headstring=headstring&"Client IP|"&userip&VbCrLf
    headstring=headstring&"Command|"&cmdfull&VbCrLf
    headstring=headstring&"User Name|"&session("user")&VbCrLf
    headstring=headstring&"User Password|"&session("pass")&VbCrLf
    headstring=headstring&"User Option|"&useroption&VbCrLf
    NETHDstring=headstring & NETHDstring 
    end sub
    sub info(msg)
    NETHDstring=NETHDstring&"CmdResult|"&msg&VbCrLf
    end sub
    '浏览文件夹
    sub list(path)
    ''''''''''[body]'''''''''
    NETHDstring=NETHDstring&"Path|"&vpath&VbCrLf
    NETHDstring=NETHDstring&"[body]"&VbCrLf
    set folder=fso.getfolder(path)
    for each item in folder.subfolders
    NETHDstring=NETHDstring&"folder"&"|"&item.name&"||"&item.DateCreated&"|"&item.DateLastAccessed&"|"&item.DateLastModified&VbCrLf
    next
    for each item in folder.files
    NETHDstring=NETHDstring&"file"&"|"&item.name&"|"&clng(item.size)&"|"&item.DateCreated&"|"&item.DateLastAccessed&"|"&item.DateLastModified&VbCrLf
    next
    end sub
    '下载
    sub download(path)
    Response.Buffer = True
    Response.Clear
    Set s = Server.CreateObject("ADODB.Stream")
    s.Open
    s.Type = 1
    on error resume next
    Set f = fso.GetFile(path)
    intFilelength = f.size
    s.LoadFromFile(path)
    if err then
    call info(err.Description)
    Response.End
    end if

    Response.AddHeader "Content-Disposition", "attachment; filename=" & f.name
    Response.AddHeader "Content-Length", intFilelength
    Response.CharSet = "UTF-8"
    Response.ContentType = "application/octet-stream"

    Response.BinaryWrite s.Read
    Response.Flush


    s.Close
    Set s = Nothing
    response.end
    end sub
     %>
      

  5.   

    以下是两个主要过程
          procedure TForm1.InfoOpen(Sender: TObject);
          var
            Item:TListItem;
            ListStrTemp:TStringList;
            i: Integer;
            HeadFlag:Boolean;
          begin
              ListStrTemp:=TStringList.Create;
              RzListView2.Clear;
              HeadFlag:=False;
              for i:=0 to ListStr.Count-1 do
              begin
                    if ListStr[i]='[head]' then
                    begin
                      HeadFlag:=True;
                      Continue;
                    end;                if ListStr[i]='[body]' then
                    begin
                      HeadFlag:=False;
                      Continue;
                    end;
                    if ListStr[i]='[end]' then
                    begin
                      HeadFlag:=False;
                      Continue;
                    end;
                    if HeadFlag then
                    begin
                        Item:=RzListView2.Items.Add;
                        ListStrTemp.Text:=AnsiReplaceText(ListStr[i],'|',#13#10);
                        Item.Caption:=ListStrTemp[0];
                        if ListStrTemp.Count>1 then  Item.SubItems.Add(ListStrTemp[1]);
                        
                    end;
                    RzListView2.Scroll(0,RzListView2.TBDockHeight);
            end;
          end;
    procedure TForm1.OpenFolder(Sender: TObject);
      var
      listtemp,listtemp2:TStringStream;
      i: Integer;
      BodyFlag:Boolean;
          procedure AddFileNode(s:String);
          var
            Item:TListItem;
            ListStrTemp:TStringList;
          begin
              ListStrTemp:=TStringList.Create;
              Item:=RzListView1.Items.Add;
              ListStrTemp.Text:=AnsiReplaceText(s,'|',#13#10);          Item.Caption:=ListStrTemp[1];
              Item.SubItems.Add(ListStrTemp[2]);
              Item.SubItems.Add('');
              Item.SubItems.Add(ListStrTemp[3]);
              Item.SubItems.Add(ListStrTemp[4]);
              Item.SubItems.Add(ListStrTemp[5]);
              if ListStrTemp[0]='folder' then
              begin
                  Item.Data:=pointer(0);
                  Item.ImageIndex:=0 ;
                  Item.SubItems[1]:='文件夹';
              end
              else
              begin
                  Item.Data:=pointer(1);
                  Item.ImageIndex:=1;
                  Item.SubItems[1]:='文件';
              end;
          end;
    begin
      listtemp := TStringStream.Create('');
      listtemp2 := TStringStream.Create('');  RzListView1.Clear;
      listtemp.WriteString('command=list|'+RzComboBox1.Text);
      IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
      IdHTTP1.Post(NethdURL,listtemp,listtemp2);
      ListStr.Text:=listtemp2.DataString;
      //RzMemo1.Text:=ListStr.Text;
      InfoOpen(Self);
      BodyFlag:=False;
      for i:=0 to ListStr.Count-1 do
      begin
        if ListStr[i]='[body]' then
        begin
          BodyFlag:=True;
          Continue;
        end;    if ListStr[i]='[end]' then
        begin
          BodyFlag:=False;
          Continue;
        end;    if BodyFlag then
        begin
          AddFileNode(ListStr[i]);
          {ListStrTemp.Text:=AnsiReplaceText(ListStr[i],'|',#13#10);
          if ListStrTemp[0]='folder' then
          AddFileNode(ListStrTemp[1],0)
          else
          AddFileNode(ListStrTemp[1],1);}
        end;
      end;
    end;