博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
INDY10的IDHttpServer应答客户端
阅读量:4329 次
发布时间:2019-06-06

本文共 1737 字,大约阅读时间需要 5 分钟。

INDY10的IDHttpServer应答客户端

首先贴源码:

procedure TIdHTTPResponseInfo.WriteContent;begin  if not HeaderHasBeenWritten then begin    WriteHeader;  end;  // RLebeau 11/23/2014: Per RFC 2616 Section 4.3:  //  // For response messages, whether or not a message-body is included with  // a message is dependent on both the request method and the response  // status code (section 6.1.1). All responses to the HEAD request method  // MUST NOT include a message-body, even though the presence of entity-  // header fields might lead one to believe they do. All 1xx  // (informational), 204 (no content), and 304 (not modified) responses  // MUST NOT include a message-body. All other responses do include a  // message-body, although it MAY be of zero length.  if not (    (FRequestInfo.CommandType = hcHEAD) or    ((ResponseNo div 100) = 1) or    (ResponseNo = 204) or    (ResponseNo = 304)    ) then  begin    // Always check ContentText first    if ContentText <> '' then begin      FConnection.IOHandler.Write(ContentText, CharsetToEncoding(CharSet));    end    else if Assigned(ContentStream) then begin      ContentStream.Position := 0;      FConnection.IOHandler.Write(ContentStream);    end    else begin      FConnection.IOHandler.WriteLn('' + IntToStr(ResponseNo) + ' ' + ResponseText    {Do not Localize}       + '', CharsetToEncoding(CharSet));    {Do not Localize}    end;  end;  // Clear All - This signifies that WriteConent has been called.  ContentText := '';    {Do not Localize}  ReleaseContentStream;end; 

一共可以应答客户端3种内容:

1)ContentText不为空字串,则发送字符串

2)ContentStream对象存在,则发送流

3)不是上面2种情况,则发送的是HTML。

最后会自动清空应答的字串或释放流,这也是为什么我们手动释放流反而会报“非法访问”错误:

ContentText := ''; 

ReleaseContentStream;

 

转载于:https://www.cnblogs.com/hnxxcxg/p/10258842.html

你可能感兴趣的文章
切换svn登录账户
查看>>
oracle配置备份
查看>>
手游后台PVP系统网络同步方案总结
查看>>
luogu1979 华容道 (dijkstra+bfs)
查看>>
ADO.NET基础必备之DataSet
查看>>
Valid Palindrome
查看>>
Python 多线程应用
查看>>
默认函数及运用
查看>>
加班与效率
查看>>
js题集8
查看>>
Rancher 1.6 版本 只能在 linux 下用
查看>>
《将博客搬至CSDN》
查看>>
异常的基本概念
查看>>
Educational Codeforces Round 4 C. Replace To Make Regular Bracket Sequence
查看>>
.Net 程序脱壳
查看>>
asp.net文本编辑器(FCKeditor)
查看>>
SEnet --se module
查看>>
【OpenStack】OpenStack系列8之Nova详解 Neutron详解
查看>>
[翻译]理解分析Linux里的101个ELF文件
查看>>
iOS Programming Subclassing UITableViewCell
查看>>