Indy 10 Http服务器示例 [英] Indy 10 Http Server sample
问题描述
我需要一个简单的代码示例为Indy 10 Http服务器当请求(post)只显示它
有没有一个Indy 9样本?
谢谢
- 开始一个新的VCL Forms项目
- 将TidHTTPServer组件删除到表单
-
双击表单以创建一个 OnCreate()事件并激活服务器
IdHTTPServer1.Active:= True;
-
返回表单,选择HTTP Server组件,创建一个 OnCommandGet 事件
在这个 OnCommandGet 在GET / POST发生时,它在子线程中调用),通过填充响应来处理请求。
AResponseInfo .ContentText:='< html>< head>< title>我的第一个响应< / title>< / head>'+
'< body>命令:'+ ARequestInfo.Command +
'< br />主机:'+ ARequestInfo.Host +
'< br /> URI:'+ ARequestInfo.URI +
'< br /> UserAgent: + ARequestInfo.UserAgent +
'< / body>< / html>';
根据您的Delphi版本,您可能还需要将 IdContext 添加到您的使用子句
运行您的演示应用程序,然后启动浏览器 http:// localhost ,你应该得到一个响应。 (除非你有其他东西在80端口听,在这种情况下你的演示程序会产生一个例外)
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
- Start a new VCL Forms project
- Drop a TidHTTPServer component onto the Form
Double-click the form to create an OnCreate() event and activate the server
IdHTTPServer1.Active := True;
Back on the form, select the HTTP Server component, and create an OnCommandGet event
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>';
Depending on your Delphi version, you may also have to add IdContext to your Uses clause
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屋!