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. QFramework 使用指南 2020(八):Res Kit(2)模拟模式与非模拟模式

    在上一篇,介绍了 Res Kit 的基本使用,相信大家已经体会到了 Res Kit 的简便之处了. 在这一篇,我们试着探讨一下 Res Kit 的设计背后原理. AssetBundle 的不便之处 在 ...

  2. python3 安装pip提示没有distutils.util模块错误的解决

    Python3 安装pip 提示ModuleNotFoundError: No module named 'distutils.util'   环境ubutun14,python版本是python3. ...

  3. java 分布式实践

    java 分布式实践 spring boot cloud实践 开源的全链路跟踪很多,比如 Spring Cloud Sleuth + Zipkin,国内有美团的 CAT 等等. 其目的就是当一个请求经 ...

  4. CF1187D Subarray Sorting

    思路: 线段树好题.对a数组中的每个元素从左到右依次操作,判断最终是否能够转化成b数组.在此过程中使用线段树维护区间最小值判断是否能够进行合法操作. 实现: #include <bits/std ...

  5. odoo12安装指南

    声明:本指南默认已安装好Python3和pycharm及postgresql,odoo12的源码包 一. 1.在pycharm创建一个新的项目 建议创建在虚拟环境中 2.在pycharm的控制台下检验 ...

  6. uwp,c#,mediaElement与slider进度条绑定

    虽然微软uwp官方已停止对传统媒体控件mediaElement的update,新控件为mediaPlayerElement和mediaPlayer[官方word:https://docs.micros ...

  7. [bzoj3060][Poi2012]Tour de Byteotia_并查集

    [Poi2012]Tour de Byteotia 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=3060 题解: 这类题有一个套路,就是 ...

  8. git 服务端安装

    服务器端创建 git 用户,用来管理 Git 服务,并为 git 用户设置密码 [root@localhost home]# id git id: git:无此用户 [root@localhost h ...

  9. Nginx05---负载均衡 upsteam

    参考   https://www.cnblogs.com/linjiqin/p/5494783.html

  10. Python 解LeetCode:23. Merge k Sorted Lists

    题目描述:把k个排序的链表组成的列表合并成一个排序的链表 思路: 使用堆排序,遍历列表,把每个列表中链表的头指针的值和头指针本身作为一个元素放在堆中: 第一步中遍历完列表后,此时堆中最多会有n个元素, ...