delphi indy TIdHTTP TIdHTTPServer Post Get  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi indy TIdHTTP TIdHTTPServer Post Get


TIdHTTPServer :

  try
    IdHTTPServer1.Bindings.Clear;
    //要绑定的端口,一定设置此项,这是真正要绑定的端口;
    IdHTTPServer1.DefaultPort:=8099;
    IdHTTPServer1.Bindings.Add.IP := '127.0.0.1';
    //启动服务器
    IdHTTPServer1.Active := True;
    Memo1.Lines.Add('启动');
  except
     showmessage('启动失败!');
  end;

procedure TForm1.IdHTTPServer1CommandGet(AContext: TIdContext;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
  Memo1.Lines.Add(ARequestInfo.Document);
  Memo1.Lines.Add(ARequestInfo.QueryParams);
  Memo1.Lines.Add(ARequestInfo.Params.Values['Par1'] );
  Memo1.Lines.Add(ARequestInfo.Params.Values['Par2'] );
  Memo1.Lines.Add(ARequestInfo.Command);
  Memo1.Lines.Add(ARequestInfo.URI);

  AResponseInfo.ContentEncoding:='utf-8';
  AResponseInfo.ContentType :='text/html';
  AResponseInfo.ContentText:='好';

  //发html文件
   {AResponseInfo.ContentEncoding:='utf-8';
   AResponseInfo.ContentType :='text/html';
   AResponseInfo.ContentText:='好'; }
   //发xml文件
   {AResponseInfo.ContentType :='text/xml';
   AResponseInfo.ContentText:=''
   +''
   +''+AnsiToUtf8('陈')+'14'
   +'bb16'
   +'';}

end;



TIdHTTP :

procedure TForm1.Button2Click(Sender: TObject);
var
  URL: string;
  StrR: string;
  RequestStream : TStringStream;
begin
  URL := 'http://172.23.4.120:8099/test';
  IdHttp1.Request.ContentType :='application/x-www-form-urlencoded';
  RequestStream := TStringStream.Create('Par1=1&Par2=2', TEncoding.UTF8);
  RequestStream.Position := 0;

  StrR := IdHTTP1.Post(URL, RequestStream);
  Memo2.Lines.Add(StrR);

  FreeAndNil(RequestStream);
end;
————————————————

原文链接:https://blog.csdn.net/gjtao1130/article/details/78613903

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.040755987167358 seconds