我在网上找了好些delphi用Tidhttp文件上传的例子,用asp接受文件,但是好像都失败了.错误信息是:socket error # 10053 software caused connection abort
delphi主要程序如下:
function TForm1.UpLoagFile(FileName: String;http:TIdhttp): string;
var
obj : TIdMultiPartFormDataStream;
Url:String;
begin
obj :=TIdMultiPartFormDataStream.Create;
try
obj.AddFile('file1',FileName,GetMIMETypeFromFile('c:\1.jpg'));
//http.Request.ContentType:=obj.RequestContentType;
http.Request.ContentType:='application/x-www-form-urlencoded';
obj.Position:=0;
//此页面负责接收上传文件
Url:='http://127.0.0.1:20000/upload.asp';
try
http.HandleRedirects := true;
http.AllowCookies := true;
Result:=http.Post(Url, obj);
except
on E:Exception do
begin
Application.MessageBox(PChar('上传文件失败,错误原因:'+ E.Message),('错误'), MB_OK + MB_ICONERROR);
Result :='';
end;
end;
finally
obj.Free;
end;
end;
--------------------------------------------------
asp文件如下:
<%
Function GetFileName(ByVal strFile)
If strFile <> "" Then
GetFileName = mid(strFile,InStrRev(strFile, "\")+1)
Else
GetFileName = ""
End If
End functionstrFileName = Request.Form("file1")
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1 ' adTypeBinary
objStream.Open
objStream.LoadFromFile strFileName
objStream.SaveToFile Server.MapPath(GetFileName(strFileName)),2
objStream.Close
%>
上传成功
--------------------------------------------------
用html直接上传成功,html文件如下
<form name="FORM" action="http://172.19.85.243" method="post">
<input type="submit" name="submit" value="OK">
<input type="file" name="file1" style="width:400" value="">
</form>
-----------------------------------------------
希望高手都过来,本人是个初学者,csdn中分数也不多,希望高手不吝赐教,真心的谢谢!!!
delphi主要程序如下:
function TForm1.UpLoagFile(FileName: String;http:TIdhttp): string;
var
obj : TIdMultiPartFormDataStream;
Url:String;
begin
obj :=TIdMultiPartFormDataStream.Create;
try
obj.AddFile('file1',FileName,GetMIMETypeFromFile('c:\1.jpg'));
//http.Request.ContentType:=obj.RequestContentType;
http.Request.ContentType:='application/x-www-form-urlencoded';
obj.Position:=0;
//此页面负责接收上传文件
Url:='http://127.0.0.1:20000/upload.asp';
try
http.HandleRedirects := true;
http.AllowCookies := true;
Result:=http.Post(Url, obj);
except
on E:Exception do
begin
Application.MessageBox(PChar('上传文件失败,错误原因:'+ E.Message),('错误'), MB_OK + MB_ICONERROR);
Result :='';
end;
end;
finally
obj.Free;
end;
end;
--------------------------------------------------
asp文件如下:
<%
Function GetFileName(ByVal strFile)
If strFile <> "" Then
GetFileName = mid(strFile,InStrRev(strFile, "\")+1)
Else
GetFileName = ""
End If
End functionstrFileName = Request.Form("file1")
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1 ' adTypeBinary
objStream.Open
objStream.LoadFromFile strFileName
objStream.SaveToFile Server.MapPath(GetFileName(strFileName)),2
objStream.Close
%>
上传成功
--------------------------------------------------
用html直接上传成功,html文件如下
<form name="FORM" action="http://172.19.85.243" method="post">
<input type="submit" name="submit" value="OK">
<input type="file" name="file1" style="width:400" value="">
</form>
-----------------------------------------------
希望高手都过来,本人是个初学者,csdn中分数也不多,希望高手不吝赐教,真心的谢谢!!!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货