为什么上传不了文件,就是17.6.1.99这个服务器在11这个文件夹下没有123.doc的文件,而浏览器输入这个地址'http://17.6.1.99:8888/11/1.asp'也是正常的,程序也不报错!
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,Idhttp, URLMon, IdMultipartFormData, StdCtrls;
const UpUrl = 'http://17.6.1.99:8888/11/1.asp';
const UpFileName = 'd:\123.doc';
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
MutPartForm: TIdMultiPartFormDataStream;
response: string;
FHttp: Tidhttp;
beginFHttp := Tidhttp.Create(nil);
FHttp.HandleRedirects := true;
FHttp.AllowCookies := true; MutPartForm := TIdMultiPartFormDataStream.Create;
MutPartForm.AddFormField('act', 'upload');
MutPartForm.AddFormField('upcount', '1');
MutPartForm.AddFormField('filepath', 'data');
MutPartForm.AddFormField('file1', 'filename='''+UpFileName+'''');
MutPartForm.AddFormField('Submit', 'Submit');
MutPartForm.AddFile('file1', UpFileName, 'text/plain');
try
response := FHttp.Post(UpUrl, MutPartForm);
Messagebox(0, PAnsiChar(response), 'ca', MB_OK);
finally
MutPartForm.Free;
FHttp.Free;
end;end;end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,Idhttp, URLMon, IdMultipartFormData, StdCtrls;
const UpUrl = 'http://17.6.1.99:8888/11/1.asp';
const UpFileName = 'd:\123.doc';
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
MutPartForm: TIdMultiPartFormDataStream;
response: string;
FHttp: Tidhttp;
beginFHttp := Tidhttp.Create(nil);
FHttp.HandleRedirects := true;
FHttp.AllowCookies := true; MutPartForm := TIdMultiPartFormDataStream.Create;
MutPartForm.AddFormField('act', 'upload');
MutPartForm.AddFormField('upcount', '1');
MutPartForm.AddFormField('filepath', 'data');
MutPartForm.AddFormField('file1', 'filename='''+UpFileName+'''');
MutPartForm.AddFormField('Submit', 'Submit');
MutPartForm.AddFile('file1', UpFileName, 'text/plain');
try
response := FHttp.Post(UpUrl, MutPartForm);
Messagebox(0, PAnsiChar(response), 'ca', MB_OK);
finally
MutPartForm.Free;
FHttp.Free;
end;end;end.
对,好像一般都是ftp上传的。
同时开httpwatch 监控 asp页面
它已经被配置为可执行了吗?子目录的权限也是web进程的账号可以读写的吗?
MutPartForm.AddFile('file1', UpFileName, 'multipart/form-data');
FHttp.Request.ContentType := MutPartForm.RequestContentType;