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格式报文的更多相关文章

  1. 利用 CURL 发送JSON格式字符串

    /* * post 发送JSON 格式数据 * @param $url string URL * @param $data_string string 请求的具体内容 * @return array ...

  2. idHTTP 向网站发送json格式数据

    idHTTP 向网站发送json格式数据 var rbody:tstringstream; begin rbody:=tstringstream.Create('{"name":& ...

  3. 如何使用python内置的request发送JSON格式的数据

    使用步骤如下: 一.如果想发送json格式的数据,需要使用request模块中的Request类来创建对象,作为urlopen函数的参数 二.header中添加content-type为applica ...

  4. 巧妙的使用jmeter来发送json格式数据

    1. header-manager 修改content-type值. 如果不修改该值, 则默认会是urlencode的数据格式(例如a=5&b=6). 修改为json后,会告诉服务器,发送的数 ...

  5. ajax发送json格式与文件数据、django自带的序列化器(了解)

    上期内容回顾 聚合查询和分组查询 # 聚合查询 max min sum avg count # 查询关键字:aggregate from django.db.models import Max, Mi ...

  6. linux c 使用socket 发送http请求 可以发送json格式数据

    #include <stdio.h>#include <sys/socket.h>#include <sys/types.h>#include <time.h ...

  7. 通过http协议发送json格式请求并解析

    本人初入门径.代码略显粗糙,欢迎指点改正! 最近在做公司的项目的时候,需要和其他公司进行业务上的对接,对方直接扔过来一个协议用来开发,最近稍微看了一下,写了一个通过协议获取数据的方法 对方的协议内容部 ...

  8. 模拟一个http 请求的json格式报文,带 rsa 签名操作

    一.对需要加密的字符串,定义RsaSignUnsign 类,代码如下: 实现了: 1.实现了生成新的pubkey.pri_key方法: 2.将新生成的keys 写入文件: 3.从文件获取pubkey. ...

  9. java请求POST发送json格式请求

    public static String upload(String url){ try { HttpClient httpclient = new DefaultHttpClient(); Http ...

随机推荐

  1. springboot-springmvc-requestParam

    springmvc请求方式 1.直接写在形参中:基本类型 @RequestMapping("/testRequestParam1") public ModelAndView tes ...

  2. PJzhang:docker基础知识的2个疗程-one

    猫宁!!! 参考:http://virtual.51cto.com/art/201805/572135.htm https://www.cnblogs.com/rkit/p/9237696.html ...

  3. BFS算法模板(python实现)

    BFS算法整理(python实现) 广度优先算法(Breadth-First-Search),简称BFS,是一种图形搜索演算算法. 1. 算法的应用场景 2. 算法的模板 2.1 针对树的BFS模板 ...

  4. 思科S系列220系列交换机多个漏洞预警

    补天漏洞响应平台近期监测思科官方发布了关于思科 S 系列 220 系列交换机的3个漏洞修复通告,其中包含2个高危漏洞,最高CVSS 3.0评分9.8. 更新时间 2019年 08月 09日 威胁目标 ...

  5. numpy中np.random.seed()的详细用法

    在进行机器学习和深度学习中,我们会经常用到np.random.seed(),利用随机数种子,使得每次生成的随机数相同. numpy.randn.randn(d0,d1,...,dn) randn函数根 ...

  6. Django之会话机制cookie、session使用

    login视图函数: def login(request): if request.method == 'POST': username = request.POST.get('username') ...

  7. 数据结构——关于任一二叉树n0=n2+1的证明

    对于任一二叉树,若度为2的结点有n2个,则叶子结点数必为n2+1 证明: 假设该二叉树总共有n个结点(n=n0+n1+n2),则该二叉树总共会有n-1条边,度为2的结点会延伸出两条边, 同理,度为1的 ...

  8. [Agc029C]Lexicographic constraints_进制_二分答案_贪心

    Lexicographic constraints 题目链接:https://atcoder.jp/contests/agc029/tasks/agc029_c 数据范围:略. 题解: 二分是显然的, ...

  9. SQL 十位随机数(大小写字母+数据)

    USE [TEST]GO/****** Object: UserDefinedFunction [dbo].[RANDTENNUMS] Script Date: 2019/7/23 15:40:16 ...

  10. 关于Linux操作系统中的一些易忘记的命令与作用

    1.改变文件或文件夹的权限,例如:chmod options mode file :[ugoa...] [+-=] [rwxXstugo],其中字符的含义如下: 第一组[ugoa...]:文件(夹)权 ...