Delphi调用HTTP接口三种参数拼接方式
2023-09-11 14:15:13 时间
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);
经实际测试后两种方法经常会遇到不好使的情况。第一种笨方法最有效。
相关文章
- 2、SpringBoot接口Http协议开发实战8节课(7-8)
- 针对接口编程
- ASP.NET WebApi服务接口如何防止重复请求实现HTTP幂等性
- 实现接口幂等性的几种方案
- ssm(Spring+Spring mvc+mybatis)Service层接口——IDeptService
- Dubbo 接口是什么? 与http 接口有什么区别
- [Http] Understand what an HTTP Request is
- 零配置命令行HTTP服务器 http-server
- php开发api接口
- MFC Windows 程序设计[九十五]之命令行接口调用(附源码)
- 使用 http-proxy 代理 HTTP 请求时遇到的 the requested url is invalid 错误消息
- Atitit 返回http500返回码,以及自定义返回提示 目录 1. 可以看到从php发送http响应代码的三种方法:1 1.1. Header("HTTP/1.1 404 Not Found"
- Atitit 微服务实践 艾提拉著 微服务主要解决几个问题负载均很 目录 1. 微服务的模式 http请求层 vs服务层1 1.1. Http vs 服务层优缺点1 2. 实现技术2
- 使用 http-proxy 代理 SAP UI5 应用发起的 HTTP 请求
- Springboot项目如何设计接口中敏感数据的脱敏展示?
- 〖Python接口自动化测试实战篇⑤〗- 接口自动化测试必备基础 - http协议
- springboot中service层注入的是实现类,但Controller层接收的是接口
- 【Groovy】MOP 元对象协议与元编程 ( 使用 Groovy 元编程进行函数拦截 | 实现 GroovyInterceptable 接口 | 重写 invokeMethod 方法 )
- 高清摄像头MIPI接口与ARM处理器的连接
- 【高并发】亿级流量场景下如何为HTTP接口限流?看完我懂了!!
- atitit.基于http json api 接口设计 最佳实践 总结o7
- 【问题解决】[kubelet-check] The HTTP call equal to ‘curl -sSL http://localhost:10248/healthz‘ failed wite
- 【2023骚操作教程】HTTP接口测试还可以这么玩?
- 怎样才算完整的接口自动化测试案例?
- 实现现下列哪一种接口的对象,并不需要在web.xml文件内进行额外的设定,Servlet容器就能够回应该对象加入HTTP会话所发生的事件?(选择1项)
- 单链表(配图详解每一个函数接口)