ImageVerifierCode 换一换
格式:DOCX , 页数:7 ,大小:16.83KB ,
资源ID:7160841      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/7160841.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(悲催的idhttpServer Get Post Upload 上传 multipart form post.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

悲催的idhttpServer Get Post Upload 上传 multipart form post.docx

1、悲催的idhttpServer Get Post Upload 上传 multipart form post悲催的idhttpServer Get Post Upload 上传 multipart form post 悲催的idhttpServer.Get 浏览网页编码问题.明明网页中有chaset,但中文仍然显示为乱码.必须在 ContentType中指定 chaset, AResponseInfo.CharSet 设置无效? contentType := GetMimeTypeFromFile(LocalDoc); if LeftStr(ContentType, 4) = text the

2、n begin ContentType := ContentType + ; charset=gb2312; end; AResponseInfo.ContentType := contentType;AResponseInfo.ContentText 指定为含有中文的字符串,会显示乱码.用流. AResponseInfo.ResponseNo := 404; AResponseInfo.ContentType := text/plain + ; charset=gb2312; /乱码须用流的形式 memoryStream:=TMemoryStream.Create; s:=找不到 + ARe

3、questInfo.Document; memorystream.write(PAnsichar(s),length(s); AResponseInfo.ContentStream := memorystream; AResponseInfo.ContentText := <html> + #13#10 + <body> + #13#10 + Page not found:<br> + #13#10 + <b> + ARequestInfo.Document + </b> + #13#10 + </body> + #13#

4、10 + </html>对于存在的文件,用 AResponseInfo.ServeFile(AContext, rPage)来试试看.可能可以避免乱码,未实验,估计可行?procedure TfrmMain.ServerCommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);var rPage : String;begin Log(Serving: + ARequestInfo.Document + to + AContext.Con

5、nection.Socket.Host, clBlue); if (ARequestInfo.Document <> ) and (ARequestInfo.Document <> /) and (ARequestInfo.Document <> ) then rPage := Copy(ARequestInfo.Document, 2, Length(ARequestInfo.Document) else rPage := Index.htm; rPage := StringReplace(rPage, /, ,rfReplaceAll, rfIgnore

6、Case); rPage := IncludeTrailingBackslash(edServerRoot.Text) + rPage; if FileExists(rPage) then AResponseInfo.ServeFile(AContext, rPage) else AResponseInfo.ContentText := <H1>ERROR</H1>File not found: +ARequestInfo.Document;end;Post上传文件.procedure TForm1.IdHTTPServerCreatePostStream(AConte

7、xt: TIdContext; AHeaders: TIdHeaderList; var VPostStream: TStream);begin /VPostStream:=TFileStream.Create(c:1111111,fmCreate);/会包含所有信息,不仅仅上传的文件,还有http 协议信息 VPostStream := TMemoryStream.Create;end;procedure TForm1.IdHTTPServerCommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; ARespons

8、eInfo: TIdHTTPResponseInfo);var LocalDoc: string; ByteSent: Cardinal; ResultFile: TFileStream; memoryStream: TMemoryStream; contentType: string; s: String; Decoder, NewDecoder: TIdMessageDecoder; DestStream: TStream; IdPostStream, IdDestStream: TStream; /TIdStreamVcl ; MsgEnd: Boolean; Stream: TMemo

9、ryStream; procedure DecodeFormData(const Header: string; ASourceStream: TStream); var MsgEnd: Boolean; Decoder: TIdMessageDecoder; Tmp: string; Dest: TMemoryStream; begin MsgEnd := False; Decoder := TIdMessageDecoderMIME.Create(nil); try Decoder.SourceStream := ASourceStream; Decoder.FreeSourceStrea

10、m := False; TIdMessageDecoderMIME(Decoder).MIMEBoundary := Decoder.ReadLn; /Decoder.ReadLn; repeat Decoder.ReadHeader; case Decoder.PartType of mcptUnknown: raise Exception(Unknown form data detected); mcptText: begin Tmp := Decoder.Headers.ValuesContent-Type; Dest := TMemoryStream.Create; try Decod

11、er := Decoder.ReadBody(Dest, MsgEnd); if AnsiSameText(Fetch(Tmp, ;), multipart/mixed) then DecodeFormData(Tmp, Dest) else / use Dest as needed. finally FreeAndNil(Dest); end; end; mcptAttachment: begin Tmp := ExtractFileName(Decoder.FileName); if Tmp <> then Tmp := ExtractFilePath(Application.

12、ExeName) + webupload+Tmp else Tmp := MakeTempFilename(c:temp); Dest := TMemoryStream.Create;/TFileStream.Create(Tmp, fmCreate); try NewDecoder := Decoder.ReadBody(Dest, MsgEnd); /yu add begin if NewDecoder <>nil then begin NewDecoder.SourceStream := ARequestInfo.PostStream; /yu NewDecoder.Free

13、SourceStream := False; /yu TIdMessageDecoderMIME(NewDecoder).MIMEBoundary := TIdMessageDecoderMIME(Decoder).MIMEBoundary ; end; if (Decoder <>nil) and(Decoder.Filename<>) then Dest.SaveToFile(Tmp); /yu add end Decoder.Free; Decoder := NewDecoder; finally FreeAndNil(Dest); end; end; /end;

14、 until (Decoder = nil) or MsgEnd; finally FreeAndNil(Decoder); end; end;begin LocalDoc := ExpandFileName(Edit1.Text + ARequestInfo.Document); if LocalDocLength(LocalDoc) = then Delete(LocalDoc, Length(LocalDoc), 1); if not FileExists(LocalDoc) and DirectoryExists(LocalDoc) then if FileExists(ExpandF

15、ileName(LocalDoc + /index.html) then LocalDoc := ExpandFileName(LocalDoc + /index.html) else if FileExists(ExpandFileName(LocalDoc + /index.htm) then LocalDoc := ExpandFileName(LocalDoc + /index.htm); S := ARequestInfo.ContentType; if AnsiSameText(Fetch(S, ;), multipart/form-data) then begin DecodeF

16、ormData(S, ARequestInfo.PostStream) ; end else / use request data as needed. if FileExists(LocalDoc) then begin if AnsiSameText(Copy(LocalDoc, 1, Length(edit1.text), Edit1.Text) then begin ResultFile := TFileStream.create(LocalDoc, fmOpenRead or fmShareDenyWrite); try AResponseInfo.ResponseNo := 200

17、; contentType := GetMimeTypeFromFile(LocalDoc); if LeftStr(ContentType, 4) = text then begin ContentType := ContentType + ; charset=gb2312; end; AResponseInfo.ContentType := contentType; AResponseInfo.ContentLength := ResultFile.Size; AResponseInfo.ContentStream := ResultFile; except ResultFile.Free

18、; / We must free this file since it won t be done by the web server component end; /下载文件 /ByteSent := AResponseInfo.ServeFile(AContext, LocalDoc); end; end else begin AResponseInfo.ResponseNo := 404; AResponseInfo.ContentType := text/plain + ; charset=gb2312; /乱码须用流的形式 memoryStream:=TMemoryStream.Cr

19、eate; s:=找不到 + ARequestInfo.Document; memorystream.write(PAnsichar(s),length(s); AResponseInfo.ContentStream := memorystream; AResponseInfo.ContentText := <html> + #13#10 + <body> + #13#10 + Page not found:<br> + #13#10 + <b> + ARequestInfo.Document + </b> + #13#10 + &l

20、t;/body> + #13#10 + </html> end; Memo1.Lines.Add(AReQuestInfo.Document);end;TIdMessageDecoderMIME.ReadBody跟踪发现/不大明白为啥要多加- if MIMEBoundary <> then begin BoundaryStart := - + MIMEBoundary; Do not Localize BoundaryEnd := BoundaryStart + -; Do not Localize end;实际上传文件测试发现,发送的数据流中 没有多加的-.多此

21、一举?if IsBinaryContentTransferEncoding then begin /For binary, need EOL because the default LF causes spurious CRs in the output. LLine := ReadLnRFC(VMsgEnd, EOL, ., Indy8BitEncoding); /do not localize end上传rar文件测试,发现rar文件中的单个的#10, #13字符, 全部被替换成了#13#10两个字符,结果文件变大了,rar文件也无法打开.明明已经说了IsBinaryContentTransferEncoding, 还要多此一举.搞了一天,上传也没搞好.要不自己处理post收到的数据,不用Decoder := Decoder.ReadBody(Dest, MsgEnd);idhhtp 阻塞式.可设置为非阻塞式ICS非阻塞式使用ICS V8 Gold.编译 WebDemos下的OverbyteIcsWebServ 启动OverbyteIcsWebServ.exe访问http:/localhost/formupload.html 上传正常.

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1