哪个有这样的代码,找了好久都没解决?注意:要上传的文件c:\a.jpg是定死的,不需要要选择

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, HttpProt;type
      TForm1 = class(TForm)
        http1: THttpCli;
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    const
      crlf:string=chr(13)+chr(10);
    var
      ms,bb:tmemorystream;
      buf:string;
    begin
      ms:=tmemorystream.Create;
      bb:=tmemorystream.Create;
      bb.LoadFromFile('2.jpg');//文件的数据
      bb.Position:=0;
      buf:='--7d332066021a';
      buf:=buf+crlf+'Content-Disposition: form-data; name="name"'+crlf+crlf+' name'+crlf;
      buf:=buf+'--7d332066021a'+crlf;
      buf:=buf+'Content-Disposition: form-data; name="password"'+crlf+crlf+' possword'+crlf;
      buf:=buf+'--7d332066021a'+crlf;
      buf:=buf+'Content-Disposition: form-data; name="FilePath1"; filename="F:\http 上传\2.jpg"'+crlf;
      buf:=buf+'Content-Type: image/pjpeg'+crlf+crlf;
      ms.WriteBuffer(buf[1],length(buf)); //将头部格式写进去
      ms.Position:=ms.Size;
      ms.CopyFrom(bb,bb.Size);//读入JPG文件数据
      buf:=crlf+'--7d332066021a'+crlf;//分割符
      buf:=buf+'--7d332066021a--';//结束符
      ms.Position:=ms.Size;
      ms.WriteBuffer(buf[1],length(buf));
      ms.Position:=0;
     http1.ContentTypePost:='multipart/form-data, boundary=7d332066021a';//指定entype
     http1.URL:='http://mail.digimaple.com:8080/frameserver/servlet/Upload';
     http1.SendStream:=ms;
     http1.Post;
     ms.Free;
     bb.Free;end;end.
    你看看模拟向网站发送图片、用户名、密码
      

  2.   

    Mark,前段时间我也问类似问题,怎么就没人答呢.
      

  3.   

    请问一下http1: THttpCli;
    http1是什么控件?