Indy 10 Http 服务器示例 [英] Indy 10 Http Server sample
问题描述
我需要一个简单的 Indy 10 Http Server 代码示例当请求(发布)时简单地显示它是否有 Indy 9 样本?谢谢
I need a simple code sample for Indy 10 Http Server When request (post) simply displays it Is there an Indy 9 sample for this? Thanks
推荐答案
- 开始一个新的 VCL Forms 项目
- 将一个 TidHTTPServer 组件拖放到表单上
双击表单创建一个OnCreate()事件并激活服务器
IdHTTPServer1.Active := True;
IdHTTPServer1.Active := True;
返回表单,选择 HTTP Server 组件,然后创建一个 OnCommandGet 事件
Back on the form, select the HTTP Server component, and create an OnCommandGet event
在这个 OnCommandGet 事件(每当发生 GET/POST 时在子线程内调用)中,通过填充响应来处理请求..
In this OnCommandGet event (which is called within a child thread whenever a GET/POST occurs), handle the request, by populating the response..
AResponseInfo.ContentText := '<html><head><title>My First Response</title></head>' +
'<body>Command: ' + ARequestInfo.Command +
'<br />Host: ' + ARequestInfo.Host +
'<br />URI: ' + ARequestInfo.URI +
'<br />UserAgent: ' + ARequestInfo.UserAgent +
'</body></html>';
根据您的 Delphi 版本,您可能还需要将 IdContext 添加到您的 Uses 子句
Depending on your Delphi version, you may also have to add IdContext to your Uses clause
运行您的演示应用程序,然后启动浏览器到 http://localhost,您应该会得到响应.(除非您在端口 80 上侦听其他内容,在这种情况下,您的演示应用程序将生成异常)
Run your demo app and then launch a browser to http://localhost and you should get a response. (Unless you have something else listening on Port 80 in which case your demo app will generate an exception)
这篇关于Indy 10 Http 服务器示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!