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

最新文章

  1. Zabbix监控VMare Vcenter
  2. 基于Token的身份验证——JWT
  3. 【转】【C/C++】实现memcpy函数
  4. ArcGIS生成根据点图层生成等值面并减小栅格锯齿的操作步骤
  5. php 反射
  6. iPhone和iPad版本的分辨率a
  7. 二、 C#调用存储过程
  8. HDU 5623 KK&#39;s Number (博弈DP)
  9. Truncate Table user
  10. 微型 ORM 的第二篇 DapperLambda性能测试[Dapper比较篇]
  11. Python数据类型一:数字与运算符
  12. java.lang.Exception: DEBUG STACK TRACE for PoolBackedDataSource.close().
  13. string.Format对C#字符串格式化[转]
  14. Java编程思想第四版勘误
  15. HDU--2363
  16. Cognos备份与恢复方案
  17. Underscore template
  18. 阻塞 , 非阻塞 , 同步 ,异步 , I/O模型
  19. http://www.360doc.com/content/14/0313/17/16070877_360315087.shtml
  20. handlebars.js基础学习笔记

热门文章

  1. 限流保护——nginx限流模块
  2. Hydra(爆破神器)使用方法
  3. centos(linux)-jdk配置
  4. 教你用免费的hihttps开源WEB应用防火墙阻止暴力破解密码
  5. Django用户认证模块中继承AbstractUser与AbstractBaseUser重写User表的区别
  6. mysql 触发器检测表数据添加,进而调用存储过程检测数据,进而调用存储过程添加数据
  7. Linux增加swap空间大小解决编译错误collect2:ld terminated with signal 9(或11)
  8. 什么是Java内部类?
  9. [转帖]Linux systemd 常用命令
  10. 利用js对象将iframe数据缓存, 实现子页面跳转后, 返回时不丢失之前填写的数据