上传文件,用IdHttp.Post(),为何报错:Http/1.1 500 Internal server error(200分)

  • 主题发起人 主题发起人 zlfsa
  • 开始时间 开始时间
Z

zlfsa

Unregistered / Unconfirmed
GUEST, unregistred user!
源码如下,请高手赐教
procedure TForm1.Button3Click(Sender: TObject);
var res : String;
mps : TIdMultiPartFormDataStream;
begin
inherited;
try
mps := TIdMultiPartFormDataStream.Create;
//mps.AddFormField('Description', edtDescription.Text);
mps.AddFile(edtFile.Name, edtFile.Text, edtMIMEType.Text);
mps.Position:=0;
res:=IdHTTP1.Post('http://xxxxx/xx.asp',mps);
//xxxxx/xx.asp为我的asp文件,通过htm网页调用,上传文件成功
finally
mps.Free;
end;
end;
//执行报错:Http/1.1 500 Internal server error
 
这是我写的程序的片断,估计是你的文件处理有问题
procedure TfmHttpSendFile.Upload;
var
//ResponseStream: TMemoryStream;
MultiPartFormDataStream: TMsMultiPartFormDataStream;
begin
MultiPartFormDataStream := TMsMultiPartFormDataStream.Create;
//ResponseStream := TMemoryStream.Create;
try
if (trim(edtIP.Text) <> '') and (trim(edtPort.Text) <> '') then
begin
Http.ProxyParams.ProxyServer := edtip.Text;
Http.ProxyParams.ProxyPort := StrToInt(edtPort.Text);
if (trim(edtUser.Text) <> '') and (trim(edtPwd.Text) <> '') then
begin
Http.ProxyParams.ProxyUsername := edtUser.Text;
Http.ProxyParams.ProxyPassword := edtPwd.Text;
end;
end;
Http.Request.ContentType := MultiPartFormDataStream.RequestContentType;
MultiPartFormDataStream.AddFormField('PersonName', '笑嘻嘻');
MultiPartFormDataStream.AddFormField('Description', '1111');
MultiPartFormDataStream.AddFile(edtFile.Name, edtFile.Text, 'multipart/form-data');
MultiPartFormDataStream.PrepareStreamForDispatch;
MultiPartFormDataStream.Position := 0;
try
HTTP.Post('http://xxx/Upload/fileupload.dll/Upload', MultiPartFormDataStream);
except
Application.MessageBox('网络传输失败!','错误',MB_ICONERROR);
end;
finally
MultiPartFormDataStream.Free;
//ResponseStream.Free;
end;
end;
 
谢谢xiaobiao,我已经从网上下载到一个,带源码和asp文件,问题解决了
 
接受答案了.
 
后退
顶部