过去手里有个Delphi 7写的ActiveX其中有一段用idhttp发送图片的代码,我现在用Asp.net写了个接受页面想获得idhttp发送过来的图片,在本地用VS调试挺正常,但是放到服务器上,客户端ActiveX一上传图片就报http1.1 302 found错误,加上HandleRedirects:=true;这句话倒是不报错,但是在服务器端却没有创建文件,初学不太懂这是为啥?发送代码(Delphi 7)
var
imgStream : TIdMultiPartFormDataStream;
fn:string;
begin imgStream := TIdMultiPartFormDataStream.Create;
fn:='c:\a.jpg';
imgStream.AddFile( 'Image',fn,GetMIMETypeFromFile(fn));
idhttp1.Request.ContentType := imgStream.RequestContentType;
imgStream.Position := 0;
//idhttp1.HandleRedirects:=true;
idhttp1.Post('http://86.18.0.43/ajd/UpLoadPic.aspx', imgStream);
imgStream.Free;
end;接受页面(UpLoadPic.aspx Asp.Net)
foreach(string f in Request.Files.AllKeys)
{
HttpPostedFile postFile = Request.Files[f];
if (postFile.ContentLength > 10)
{
string path = Server.MapPath("ScanPic\\" + System.DateTime.Today.ToString("yyyy-MM-dd"));
DirectoryInfo di = new DirectoryInfo(path);
if (di.Exists == false)
di.Create(); postFile.SaveAs(path + "\\b.jpg"); }
}
var
imgStream : TIdMultiPartFormDataStream;
fn:string;
begin imgStream := TIdMultiPartFormDataStream.Create;
fn:='c:\a.jpg';
imgStream.AddFile( 'Image',fn,GetMIMETypeFromFile(fn));
idhttp1.Request.ContentType := imgStream.RequestContentType;
imgStream.Position := 0;
//idhttp1.HandleRedirects:=true;
idhttp1.Post('http://86.18.0.43/ajd/UpLoadPic.aspx', imgStream);
imgStream.Free;
end;接受页面(UpLoadPic.aspx Asp.Net)
foreach(string f in Request.Files.AllKeys)
{
HttpPostedFile postFile = Request.Files[f];
if (postFile.ContentLength > 10)
{
string path = Server.MapPath("ScanPic\\" + System.DateTime.Today.ToString("yyyy-MM-dd"));
DirectoryInfo di = new DirectoryInfo(path);
if (di.Exists == false)
di.Create(); postFile.SaveAs(path + "\\b.jpg"); }
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货