zoukankan      html  css  js  c++  java
  • TWinHttp之二

    TWinHttp之二

    function EncodeParams(strings: TStrings): SockString;
    var
    i: Integer;
    S: string;
    begin
    for i := 0 to strings.Count - 1 do
    begin
    S := strings.Names[i];
    if Length(strings.Values[S]) > 0 then
    begin
    strings.Values[S] := UrlEncode(strings.Values[S]);
    end;
    if Result = '' then
    Result := strings[i]
    else
    Result := Result + '&' + strings[i];
    end;
    end;

    function httppost(const url, password: SockString; params: TStrings; var ResponseData: SockString): Integer;
    var
    aURI: TURI;
    http: TWinHTTP;
    head: SockString;
    begin
    http := nil;
    try
    aURI.From(url);
    http := TWinHTTP.Create(aURI.Server, aURI.Port, aURI.Https);
    http.AuthUserName := 'cxg';
    http.AuthPassword := '929';
    http.IgnoreSSLCertificateErrors := true;
    Result := http.Request(aURI.Address, 'POST', 0, '', EncodeParams(params), password, head, ResponseData);
    finally
    aURI.Clear;
    http.Free;
    end;
    end;

    function httpget(const fullurl, password: SockString; var ResponseData: SockString): Integer;
    var
    aURI: TURI;
    http: TWinHTTP;
    head: SockString;
    begin
    http := nil;
    try
    aURI.From(fullurl);
    http := TWinHTTP.Create(aURI.Server, aURI.Port, aURI.Https);
    http.IgnoreSSLCertificateErrors := true;
    Result := http.Request(aURI.Address, 'GET', 0, '', '', password, head, ResponseData);
    finally
    aURI.Clear;
    http.Free;
    end;
    end;

    procedure getQry(const url, sql: string; var data: SockString);
    var
    aurl: string;
    begin
    aurl := url + 'query?sql=' + UrlEncode(sql);
    if httpget(aurl, 'yn', data) = 404 then
    begin
    ShowMessage('登陆中间件验证失败');
    Abort;
    end;
    end;

    procedure postQry(const url, sql: string; var data: SockString);
    var
    aurl: string;
    params: TStrings;
    begin
    params := TStringList.Create;
    try
    params.Add('sql=' + sql);
    aurl := url + 'query';
    if httppost(aurl, 'yn', params, data) = 333 then
    begin
    ShowMessage('登陆中间件验证失败');
    Abort;
    end;
    finally
    params.Free;
    end;
    end;

    procedure postExecute(const url, sql: string; var data: SockString);
    var
    aurl: string;
    params: TStrings;
    begin
    params := TStringList.Create;
    try
    params.Add('sql=' + sql);
    aurl := url + 'execute';
    if httppost(aurl, 'yn', params, data) = 333 then
    begin
    ShowMessage('登陆中间件验证失败');
    Abort;
    end;
    finally
    params.Free;
    end;
    end;

  • 相关阅读:
    【codeforces 797C】Minimal string
    【codeforces 797E】Array Queries
    【codeforces 796C】Bank Hacking(用一些技巧来代替multiset)
    【POJ 1860】Currency Exchange
    【微软2017年预科生计划在线编程笔试 A】Legendary Items
    【微软2017年预科生计划在线编程笔试 B】Tree Restoration
    【codeforces 797D】Broken BST
    【[Offer收割]编程练习赛11 C】岛屿3
    【[Offer收割]编程练习赛11 B】物品价值
    【codeforces 789D】Weird journey
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/8056510.html
Copyright © 2011-2022 走看看