TRestClient

TRestClient

Delphi XE6开始,REST Client系列元件渐渐开始成为 Delphi 团队的重点开发项目之一。TRESTClient, TRESTRequest, TRESTResponse 系列组合。

var
  jo: TJSONObject;
begin
  jo:= TJSONObject.Create;
  try
    ResetRESTComponentsToDefaults;
 
    RESTClient.BaseURL := 'http://ynmiddle:9999/';
    RESTClient.Authenticator := HTTPBasicAuthenticator1;
    RESTClient.ContentType := 'application/x-www-form-urlencoded';
 
    RESTRequest.Method := TRESTRequestMethod.rmPOST;
    RESTRequest.Resource := 'oauth/token';
 
    HTTPBasicAuthenticator1.Username := 'orbid-hml';
    HTTPBasicAuthenticator1.Password := EmptyStr;
 
    jo.AddPair('scope', 'product:show stock:save stock:update warehouse:list warehouse:save warehouse:show '+
                                 'warehouse:update partnerOrder:show partnerOrder:list partnerOrder:update');
    jo.AddPair('grant_type', 'client_credentials');
 
    RESTRequest.Params.Clear;
    RESTRequest.Params.AddHeader('authorization', 'Basic '+Edt_Base64.Text);
    RESTRequest.AddBody(jo);
 
 
    RESTRequest.Execute;
    memLog.Text:=RESTResponse1.Content;
  finally
    FreeAndNil(jo);
  end;
end;

  

原文地址:https://www.cnblogs.com/hnxxcxg/p/13447634.html