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;
procedure TForm1.Button4Click(Sender: TObject); var url,Timestamp,Signature,seckey: string; param:Tstringlist; begin url:='https://mws.amazonservices.com/Orders/2013-09-01'; self.NetHTTPRequest1.Accept := 'text/html, application/xhtml+xml, */*'; self.NetHTTPRequest1.url := url; self.NetHTTPRequest1.MethodString := 'POST'; seckey:='seckey'; param:=Tstringlist.Create; param.Add('AWSAccessKeyId=AWSAccessKeyId'); param.Add('Action=GetOrder'); param.Add('SellerId=SellerId'); param.Add('MWSAuthToken=MWSAuthToken'); param.Add('SignatureVersion=2'); param.Add('Timestamp='+DateToISO8601(now,true)); param.Add('Version=2013-09-01'); param.Add('SignatureMethod=HmacSHA256'); param.Add('AmazonOrderId.Id.1=AmazonOrderId.Id.1'); Signature:=system.hash.THashSHA2.GetHMAC('mws.amazonservices.com/Orders/2013-09-01'+param.Text,seckey) ; Signature:=Data.Cloud.CloudAPI.Encode64(Signature); param.Add('Signature='+Signature); edit1.Text:=signature; edit2.Text:=system.hash.THashSHA2.GetHMAC(trim(memo1.Text),seckey) ; //memo1.Text:='mws.amazonservices.com/Orders/2013-09-01'+param.Text; //Signature:=Data.Cloud.CloudAPI.TCloudSHA256Authentication.GetHashSHA256Hex('mws.amazonservices.com/Orders/2013-09-01'+param.Text); self.Memo2.Text := self.NetHTTPRequest1.Post(url, param).ContentAsString(tencoding.UTF8); end;
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/p/13447634.html