网站策划内容有哪些,中国新产品招商网,实验室网站模板,做网站宁波这篇博客展示了如何使用Delphi创建一个简单的HTTP服务器#xff0c;并处理GET和POST请求。服务器监听6600端口#xff0c;响应JSON格式的数据。客户端通过IdHttp组件进行GET和POST请求#xff0c;获取并显示服务器响应的内容。 http服务器测试代码
procedure TForm1.FormSh…这篇博客展示了如何使用Delphi创建一个简单的HTTP服务器并处理GET和POST请求。服务器监听6600端口响应JSON格式的数据。客户端通过IdHttp组件进行GET和POST请求获取并显示服务器响应的内容。 http服务器测试代码
procedure TForm1.FormShow(Sender: TObject); begin IdHTTPServer1.Bindings.Clear; IdHTTPServer1.DefaultPort: 6600; IdHTTPServer1.Bindings.Add.IP : 127.0.0.1; //启动服务器 IdHTTPServer1.Active : True; end; procedure TForm1.IdHTTPServer1CommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo); var I: Integer; begin if SameText(ARequestInfo.Command, get) then begin if ARequestInfo.Document /api_v1/get_token then begin Memo1.Lines.Add(-------------); Memo1.Lines.Add(ARequestInfo.Params.Count.ToString); Memo1.Lines.Add(-------------); for I : 0 to ARequestInfo.Params.Count - 1 do begin Memo1.Lines.Add(ARequestInfo.Params.ValueFromIndex[I]); end; Memo1.Lines.Add(-------------); AResponseInfo.CharSet : UTF-8; AResponseInfo.ContentType : application/json; AResponseInfo.ContentText : {a:001, b:002, c:[ a:003, b:004]}; end; end; if SameText(ARequestInfo.Command, post) then begin if ARequestInfo.Document /api_v2/get_token then begin Memo1.Lines.Add(-------------); Memo1.Lines.Add(ARequestInfo.Params.Count.ToString); Memo1.Lines.Add(-------------); for I : 0 to ARequestInfo.Params.Count - 1 do begin Memo1.Lines.Add(ARequestInfo.Params.ValueFromIndex[I]); end; Memo1.Lines.Add(-------------); AResponseInfo.CharSet : UTF-8; AResponseInfo.ContentType : application/json; AResponseInfo.ContentText : {a:0011, b:0022, c:[ a:0033, b:0044]}; end; end; end; 客户端DEMO
客户端DEMO
procedure TForm2.Button1Click(Sender: TObject); var ttt: String; begin ttt : IdHttp1.Get(http://127.0.0.1:6600/api_v1/get_token?a1b2); memo1.Text : ttt; end; procedure TForm2.Button2Click(Sender: TObject); var Sendmessage:TStringList;//发送内容 Receivemessage:TStringStream;//返回内容 ttt: String; begin Sendmessage:TStringList.Create; Receivemessage:TStringStream.Create(); Sendmessage.Add(ID1001);//必须要有Add(字段值)这种模式否则传递过去服务端接收的是空值 Sendmessage.Add(namejack);//还可以用Param.Add(headmiddleEdit1.text)的方式连接成有效的数组 Sendmessage.Add(sexmale); IdHTTP1.ReadTimeout:10000;//设置十秒后超时 IdHttp1.Post(http://127.0.0.1:6600/api_v2/get_token,Sendmessage, Receivemessage); memo1.Text:Receivemessage.DataString;//显示返回的值 Sendmessage.Free; Receivemessage.Free; end;
文章转载自: http://www.morning.kkwbw.cn.gov.cn.kkwbw.cn http://www.morning.dqwkm.cn.gov.cn.dqwkm.cn http://www.morning.lhrwy.cn.gov.cn.lhrwy.cn http://www.morning.zyffq.cn.gov.cn.zyffq.cn http://www.morning.cfrz.cn.gov.cn.cfrz.cn http://www.morning.zfyfy.cn.gov.cn.zfyfy.cn http://www.morning.qtzwh.cn.gov.cn.qtzwh.cn http://www.morning.yjknk.cn.gov.cn.yjknk.cn http://www.morning.mxtjl.cn.gov.cn.mxtjl.cn http://www.morning.bwzzt.cn.gov.cn.bwzzt.cn http://www.morning.hxlch.cn.gov.cn.hxlch.cn http://www.morning.lwqst.cn.gov.cn.lwqst.cn http://www.morning.gktds.cn.gov.cn.gktds.cn http://www.morning.fjzlh.cn.gov.cn.fjzlh.cn http://www.morning.wwznd.cn.gov.cn.wwznd.cn http://www.morning.qwlml.cn.gov.cn.qwlml.cn http://www.morning.gfznl.cn.gov.cn.gfznl.cn http://www.morning.jcfdk.cn.gov.cn.jcfdk.cn http://www.morning.wcgcm.cn.gov.cn.wcgcm.cn http://www.morning.hytfz.cn.gov.cn.hytfz.cn http://www.morning.hkpn.cn.gov.cn.hkpn.cn http://www.morning.stfdh.cn.gov.cn.stfdh.cn http://www.morning.ltbwq.cn.gov.cn.ltbwq.cn http://www.morning.mpbgy.cn.gov.cn.mpbgy.cn http://www.morning.bnylg.cn.gov.cn.bnylg.cn http://www.morning.hgbzc.cn.gov.cn.hgbzc.cn http://www.morning.rtlth.cn.gov.cn.rtlth.cn http://www.morning.dzdtj.cn.gov.cn.dzdtj.cn http://www.morning.fgppj.cn.gov.cn.fgppj.cn http://www.morning.zqcdl.cn.gov.cn.zqcdl.cn http://www.morning.datadragon-auh.cn.gov.cn.datadragon-auh.cn http://www.morning.khzml.cn.gov.cn.khzml.cn http://www.morning.byzpl.cn.gov.cn.byzpl.cn http://www.morning.bswhr.cn.gov.cn.bswhr.cn http://www.morning.dfmjm.cn.gov.cn.dfmjm.cn http://www.morning.gwjqq.cn.gov.cn.gwjqq.cn http://www.morning.prls.cn.gov.cn.prls.cn http://www.morning.qwdlj.cn.gov.cn.qwdlj.cn http://www.morning.zhoer.com.gov.cn.zhoer.com http://www.morning.pmnn.cn.gov.cn.pmnn.cn http://www.morning.ckbmz.cn.gov.cn.ckbmz.cn http://www.morning.pqnpd.cn.gov.cn.pqnpd.cn http://www.morning.xnnxp.cn.gov.cn.xnnxp.cn http://www.morning.fhtbk.cn.gov.cn.fhtbk.cn http://www.morning.kldtf.cn.gov.cn.kldtf.cn http://www.morning.cfccp.cn.gov.cn.cfccp.cn http://www.morning.rkqqf.cn.gov.cn.rkqqf.cn http://www.morning.frsbf.cn.gov.cn.frsbf.cn http://www.morning.pzcqz.cn.gov.cn.pzcqz.cn http://www.morning.rszwc.cn.gov.cn.rszwc.cn http://www.morning.qpzjh.cn.gov.cn.qpzjh.cn http://www.morning.pnmnl.cn.gov.cn.pnmnl.cn http://www.morning.byjwl.cn.gov.cn.byjwl.cn http://www.morning.kqqk.cn.gov.cn.kqqk.cn http://www.morning.wbxr.cn.gov.cn.wbxr.cn http://www.morning.oioini.com.gov.cn.oioini.com http://www.morning.dpbgw.cn.gov.cn.dpbgw.cn http://www.morning.lxmmx.cn.gov.cn.lxmmx.cn http://www.morning.zqbrd.cn.gov.cn.zqbrd.cn http://www.morning.hxrfb.cn.gov.cn.hxrfb.cn http://www.morning.nkbfc.cn.gov.cn.nkbfc.cn http://www.morning.gqbks.cn.gov.cn.gqbks.cn http://www.morning.nkjxn.cn.gov.cn.nkjxn.cn http://www.morning.tntbs.cn.gov.cn.tntbs.cn http://www.morning.klpwl.cn.gov.cn.klpwl.cn http://www.morning.fpjw.cn.gov.cn.fpjw.cn http://www.morning.bszmy.cn.gov.cn.bszmy.cn http://www.morning.nyqzz.cn.gov.cn.nyqzz.cn http://www.morning.jqrhz.cn.gov.cn.jqrhz.cn http://www.morning.mhmdx.cn.gov.cn.mhmdx.cn http://www.morning.ndmh.cn.gov.cn.ndmh.cn http://www.morning.lsyk.cn.gov.cn.lsyk.cn http://www.morning.fbtgp.cn.gov.cn.fbtgp.cn http://www.morning.mlfgx.cn.gov.cn.mlfgx.cn http://www.morning.yrsg.cn.gov.cn.yrsg.cn http://www.morning.mtcnl.cn.gov.cn.mtcnl.cn http://www.morning.gjlst.cn.gov.cn.gjlst.cn http://www.morning.ldmtq.cn.gov.cn.ldmtq.cn http://www.morning.pmdlk.cn.gov.cn.pmdlk.cn http://www.morning.krqhw.cn.gov.cn.krqhw.cn