Delphi调用HTTP接口三种参数拼接方式  
官方Delphi 学习QQ群: 682628230(三千人)
频道

Delphi调用HTTP接口三种参数拼接方式


Delphi调用HTTP接口三种参数拼接方式


1,常规的+号连接运算符拼接


  URL:=URL+'&eid='+FEID+'&templatecode='+TemplateCode+'&phone='+sPhone;

  URL:=URL+'&signature='+signature+'&sign_name='+FSignName+'&timestamp='+sTimestamp+'&canshu='+sParam.AsString;

  或者直接使用Format格式化拼接

  URL:=Format('http://sms.xxx.com/index/xxx.php?request=%s&eid=%s&templatecode=%s&phone=%s&signature=%s&sign_name=%s&timestamp=%s&canshu=%s',

              ['public.xxx.action',  FEID,  TemplateCode,

               sPhone,  Signature,   FSignName, sTimestamp, sParam.AsString]);

2,使用TIdMultiPartFormDataStream,需要引用IdMultipartFormData单元


Param:= TIdMultiPartFormDataStream.Create;

 

  Param.AddFormField('request', 'public.xxxx.action');

  Param.AddFormField('eid', FEID);

  Param.AddFormField('templatecode', TemplateCode);

  Param.AddFormField('phone', sPhone);

  Param.AddFormField('signature', signature);

  Param.AddFormField('sign_name', FSignName);

  Param.AddFormField('timestamp', sTimestamp);

  Param.AddFormField('canshu', sParam.AsString);

 

idHttp1.Post(URL, Param, ResponseStream);



3,使用TStringList拼接参数


ParamList := TStringList.Create;

 

    ParamList.Add('request=public.xxx.action');

    ParamList.Add('eid='+ FEID);

    ParamList.Add('templatecode='+ TemplateCode);

    ParamList.Add('phone='+ sPhone);

    ParamList.Add('signature=' + Signature);

    ParamList.Add('sign_name=' + FSignName);

    ParamList.Add('timestamp=' + sTimestamp);

    ParamList.Add('canshu=' + sParam.AsString);

 

idHTTP1.Post(URL, ParamList, ResponseStream);

经实际测试后两种方法经常会遇到不好使的情况。第一种笨方法最有效。

————————————————


原文链接:https://blog.csdn.net/wh445306/article/details/114954482



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

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

执行时间: 0.034198045730591 seconds