当前位置: 首页> 文旅> 酒店 > 如何设计一个网页里面有很多小工具_网站建设的代理_百度怎么搜索网址打开网页_优化 英语

如何设计一个网页里面有很多小工具_网站建设的代理_百度怎么搜索网址打开网页_优化 英语

时间:2025/7/9 15:44:11来源:https://blog.csdn.net/u014608435/article/details/144183774 浏览次数:0次
如何设计一个网页里面有很多小工具_网站建设的代理_百度怎么搜索网址打开网页_优化 英语

POST

function HttpPost(sUrl, sJson: string): string;
varJsonToSend: TStringStream;idHttp1: TIdHTTP;
beginEnterCriticalSection(gPostCritDML);tryJsonToSend := TStringStream.Create(sJson, TEncoding.UTF8);Result := '';tryidHttp1 := TIdHTTP.Create(nil);idHttp1.HTTPOptions := [hoKeepOrigProtocol, hoForceEncodeParams];idHttp1.ConnectTimeout := 2000;idHttp1.Response.ContentType := 'application/json;charset=utf-8';idHttp1.Request.Accept := 'application/json;charset=utf-8';idHttp1.Request.ContentType := 'application/json;charset=utf-8';idHttp1.Request.CharSet := 'utf-8';tryResult := idHttp1.Post(sUrl, JsonToSend);excepton E: Exception dobeginSaveLogMsg('与后台服务通讯异常!' + e.Message);end;end;finallyFreeAndNil(JsonToSend);end;finallyidHttp1.Free;LeaveCriticalSection(gPostCritDML);end;
end;

sJson是JSON格式的字符串,例如:sJson := '{"factoryTag":"02","num":1}'

GET

function HttpGet(sUrl: string): string;
varidHttp1: TIdHTTP;
beginEnterCriticalSection(gGetCritDML);tryResult := '';idHttp1 := TIdHTTP.Create(nil);idHttp1.HTTPOptions := [hoKeepOrigProtocol, hoForceEncodeParams];idHttp1.ConnectTimeout := 2000;idHttp1.Response.ContentType := 'application/json;charset=utf-8';idHttp1.Request.Accept := 'application/json;charset=utf-8';idHttp1.Request.ContentType := 'application/json;charset=utf-8';idHttp1.Request.CharSet := 'utf-8';tryResult := idHttp1.Get(sUrl);excepton E: Exception dobeginSaveLogMsg(sUrl);SaveLogMsg('与后台服务通讯异常!' + e.Message);end;end;finallyidHttp1.Free;LeaveCriticalSection(gGetCritDML);end;
end;

JSON解析

导入System.JSON

function GetProduceId(cName: string; localComm: CLocalComm): string;
varsRsp, sJson: string;jRet: TJSONObject;
beginResult := '';sJson := '{"factoryTag":"02","num":1}';sRsp := HttpPost(ReadConfStr('url', 'sc_url') + 'productIdBd', sJson);if (sRsp <> '') and (Pos('{', sRsp) > 0) and (Pos('}', sRsp) > 0) thenbeginjRet := TJSONObject.ParseJSONValue(sRsp) as TJSONObject;if jRet.GetValue('code').Value = '0000' thenbeginend;end;
end;

关键字:如何设计一个网页里面有很多小工具_网站建设的代理_百度怎么搜索网址打开网页_优化 英语

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: