delphi Tidhttp 发送json格式报文
type
TwmsThreadpostJson = class(TThread)
private
Furl: string;
Fpostcmd: string;
FResult: string;
FBOOL: Boolean;
protected
procedure Execute; override;
end; class function TWmsApplicationfunction.postjson(url, postcmd: string): string;
var
FThread: TwmsThreadpostJson;
begin
if booleanshowflash then
cxSetSplashVisibility(Application.MainForm <> nil, '');
try
FThread := TwmsThreadpostJson.Create;
FThread.Furl := url;
FThread.Fpostcmd := postcmd;
FThread.FBOOL := False;
FThread.Resume; while true do
begin
Application.ProcessMessages;
if FThread.FBOOL then //等待子线程执行完毕
begin
cxSetSplashVisibility(False, '');
Result := FThread.FResult;
FThread.Free;
Break;
end;
end;
except end procedure TwmsThreadpostJson.Execute;
var
strStream: TStringStream;
strStream1: TStringStream;
IdHTTP: Tidhttp;
AJson: TQJson;
passuess: boolean;
strData: string;
Strtemp: string;
strRadom: string;
strDes: string;
pub, pri: TFGInt;
begin
Fresult := '';
IdHTTP := Tidhttp.create(nil);
try
IdHTTP.Request.CustomHeaders.clear;
IdHTTP.Request.RawHeaders.values['Cookie'] := yundawms.returncookek;
IdHTTP.HandleRedirects := true;
IdHTTP.Request.CustomHeaders.Add('Cookie: ' + yundawms.returncookek);
IdHTTP.Request.Connection := 'Keep-Alive';
IdHTTP.Request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon)';
// IdHTTP.Request.ContentType:='application/x-www-form-urlencoded;charset=UTF-8';
IdHTTP.Request.Accept := 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/msword, */*';
IdHTTP.Request.AcceptLanguage := 'zh-cn';
IdHTTP.Request.AcceptEncoding := 'gzip, deflate';
IdHTTP.Request.CacheControl := 'no-cache';
IdHTTP.ReadTimeout := ;
IdHTTP.ConnectTimeout := ;
IdHTTP.Request.ContentType := 'application/json;charset=UTF-8';
IdHTTP.Request.AcceptCharSet := 'UTF-8';
IdHTTP.Request.AcceptEncoding := 'UTF-8';
IdHTTP.Request.AcceptLanguage := 'UTF-8';
IdHTTP.Request.CharSet := 'UTF-8';
// IdHTTP1.CookieManager := IdCookieManager1;
IdHTTP.HTTPOptions := IdHTTP.HTTPOptions + [hoKeepOrigProtocol]; // 关键这行
IdHTTP.ProtocolVersion := pv1_;
AJson := TQJson.Create;
passuess := false;
try
AJson.Parse(Fpostcmd);
if Assigned(AJson.ItemByPath('username')) then
AJson.ItemByPath('username').value := Tyundawms.getwmsuser;
Strtemp := inttostr(ConvertDelphiDateTimeToJavaDateTime(now));
try
AJson.AddVariant('dateTime', Strtemp);
except end; strData := Tyundawms.getwmsuser + Tyundawms.getwmspassword + Strtemp;
AJson.AddVariant('validation', TWmsApplicationfunction.Getmd5(strData));
passuess := true;
Fpostcmd := AJson.AsString;
if passuess = true then
strStream := TStringStream.create(Fpostcmd, TEncoding.UTF8)
else
exit;
finally
AJson.Free;
end;
try
yundawms.AppService.GeneralUtility.retmain('log:post' + ' url:' + Furl + ' date:' + Fpostcmd);
except
// raise Exception.Create('postjson:记录日志异常!');
end; strStream1 := TStringStream.create('', TEncoding.UTF8);
try
IdHTTP.Post(Furl, strStream, strStream1);
Fresult := strStream1.DataString; Fresult := StringReplace(Fresult, '\u008F', '', [rfReplaceAll]); //含有的特殊字符 替换为空
Fresult := StringReplace(Fresult, '\u00A0', ' ', [rfReplaceAll]); //含有全角字符替换 全角字符会乱码
except
raise Exception.Create('postjson:服务器链接失败,请检查【网络】是否正常!');
Fresult := '';
end; try
yundawms.AppService.GeneralUtility.retmain('log:get' + ' url:' + Furl + ' resultdate:' + Fresult);
except
end;
finally
IdHTTP.Disconnect;
if Assigned(IdHTTP) then
freeandnil(IdHTTP);
if Assigned(strStream) then
freeandnil(strStream);
if Assigned(strStream1) then
freeandnil(strStream1);
FBOOL := True;
end;
end;
转:https://www.cnblogs.com/yangxuming/p/8086779.html
delphi Tidhttp 发送json格式报文的更多相关文章
- 利用 CURL 发送JSON格式字符串
/* * post 发送JSON 格式数据 * @param $url string URL * @param $data_string string 请求的具体内容 * @return array ...
- idHTTP 向网站发送json格式数据
idHTTP 向网站发送json格式数据 var rbody:tstringstream; begin rbody:=tstringstream.Create('{"name":& ...
- 如何使用python内置的request发送JSON格式的数据
使用步骤如下: 一.如果想发送json格式的数据,需要使用request模块中的Request类来创建对象,作为urlopen函数的参数 二.header中添加content-type为applica ...
- 巧妙的使用jmeter来发送json格式数据
1. header-manager 修改content-type值. 如果不修改该值, 则默认会是urlencode的数据格式(例如a=5&b=6). 修改为json后,会告诉服务器,发送的数 ...
- ajax发送json格式与文件数据、django自带的序列化器(了解)
上期内容回顾 聚合查询和分组查询 # 聚合查询 max min sum avg count # 查询关键字:aggregate from django.db.models import Max, Mi ...
- linux c 使用socket 发送http请求 可以发送json格式数据
#include <stdio.h>#include <sys/socket.h>#include <sys/types.h>#include <time.h ...
- 通过http协议发送json格式请求并解析
本人初入门径.代码略显粗糙,欢迎指点改正! 最近在做公司的项目的时候,需要和其他公司进行业务上的对接,对方直接扔过来一个协议用来开发,最近稍微看了一下,写了一个通过协议获取数据的方法 对方的协议内容部 ...
- 模拟一个http 请求的json格式报文,带 rsa 签名操作
一.对需要加密的字符串,定义RsaSignUnsign 类,代码如下: 实现了: 1.实现了生成新的pubkey.pri_key方法: 2.将新生成的keys 写入文件: 3.从文件获取pubkey. ...
- java请求POST发送json格式请求
public static String upload(String url){ try { HttpClient httpclient = new DefaultHttpClient(); Http ...
随机推荐
- Paid consultation (currently free 20190901)
Master of Electrical Engineering, Chongqing University Range:01 College entrance examination, major, ...
- HNOI 2012/codevs 1994:排队
题目描述 Description 某中学有n 名男同学,m 名女同学和两名老师要排队参加体检.他们排成一条直线,并且任意两名女同学不能相邻,两名老师也不能相邻,那么一共有多少种排法呢?(注意:任意两个 ...
- JavaSE基础(六)--Java流程控制语句之条件语句
Java 条件语句 - if...else 一个 if 语句包含一个布尔表达式和一条或多条语句. 语法 if 语句的语法如下: if(布尔表达式) { //如果布尔表达式为true将执行的语句 } 如 ...
- [LuoguP2159][SHOI2009]舞会_动态规划_高精度_排列组合
舞会 题目链接:https://www.luogu.org/problem/P2159 数据范围:略. 题解: 不会.... 看了题解觉得自己好傻逼啊
- [转帖]四个修改Docker默认存储位置的方法
四个修改Docker默认存储位置的方法 https://blog.51cto.com/forangela/1949947 易改乾坤关注0人评论27435人阅读2017-07-22 09:18:48 ...
- 自然语言处理工具HanLP-基于层叠HMM地名识别
本篇接上一篇内容<HanLP-基于HMM-Viterbi的人名识别原理介绍>介绍一下层叠隐马的原理. 首先说一下上一篇介绍的人名识别效果对比: 1. 只有Jieba识别出的人名 准确率极低 ...
- flink两种安装方式
Flink Standalone 集群 HA 配置 1. HA 集群环境规划 使用三台节点实现两主两从集群(由于笔记本性能限制,不能开启太多虚拟机,其实使用三 台和四台机器在安装配置上没有本质区别) ...
- 2019年08月21日 服务部署笔记 请求打不到域名后某个pod上
背景: 一个小项目http+https的小项目, 需要配置域名, 因http 和 https服务共存, 所以决定域名后面挂两个不同的LVS, 80端口一个, 443端口一个. 服务框架: nginx服 ...
- [转]Life of a binary
发现一篇讲程序生命周期的文章,感觉蛮不错.
- 学习GTK+ (1) ——编写helloworld
环境 我使用的是新安装的manjaro 18.1 (kde版),安装新系统后后直接可以开始写代码,不需要安装各种调用的库等. 推荐一个网站,gnome开发者 https://developer.gno ...