Delphi调用HTTP接口三种参数拼接方式
1,常规的+号连接运算符拼接
URL:=URL+'&eid='+FEID+'&templatecode='+TemplateCode+'&phone='+sPhone; URL:=URL+'&signature='+signature+'&sign_name='+FSignName+'×tamp='+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×tamp=%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);
经实际测试后两种方法经常会遇到不好使的情况。第一种笨方法最有效。
本文来自博客园,作者:IT情深,转载请注明原文链接:https://www.cnblogs.com/wh445306/p/16751702.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义