REST API and Delphi error: Required OAuth credentials not provided
REST API and Delphi error: Required OAuth credentials not provided
我需要在 FireMonkey 中实现一个 REST API 来获取一些信息,但我不确定我该怎么做。
REST API 使用 OAuth2,我有 ACESS_TOKEN 但不工作
<ams:fault xmlns:ams="http://wso2.org/apimanager/security"><ams:code>900902</ams:code><ams:message>Missing Credentials</ams:message><ams:description>Required OAuth credentials not provided. Make sure your API invocation call has a header: "Authorization: Bearer ACCESS_TOKEN"</ams:description></ams:fault>
var
LClient: TRESTClient;
LRequest: TRESTRequest;
LResponse: TRESTResponse;
begin
LClient := TRESTClient.Create('https://apigateway.serpro.gov.br/consulta-cnpj-
df/v1/cnpj/99999999999999');
try
LRequest := TRESTRequest.Create(LClient);
try
LResponse := TRESTResponse.Create(LClient);
try
LRequest.Client := LClient;
LRequest.Response := LResponse;
LRequest.Accept:='application/json';
LRequest.Params.AddHeader('Authorization', 'Bearer 6315a3c9c2e4bb2e0816da132828f269');
LRequest.Method := rmGET;
LRequest.Execute;
Memo1.Clear;
Memo1.Lines.Add(IntToStr(LResponse.StatusCode) + ' / ' + LResponse.StatusText);
Memo1.Lines.Add(LResponse.Headers.Text);
Memo1.Lines.Add('--------------------------------------------------------------');
Memo1.Lines.Add(LResponse.Content);
finally
LResponse.Free;
end;
finally
LRequest.Free;
end;
finally
LClient.Free;
end;
end;
有人可以帮助我吗?
Auth header 需要在不编码的情况下发送,所以使用 AddItem
而不是 AddHeader
LRequest.Params.AddItem ('Authorization', 'Bearer ' + YourToken, pkHTTPHEADER, [poDoNotEncode]);
Embarcadero REST 框架可能令人困惑。我也没有长时间使用 REST,所以我自己仍在努力。
我需要在 FireMonkey 中实现一个 REST API 来获取一些信息,但我不确定我该怎么做。
REST API 使用 OAuth2,我有 ACESS_TOKEN 但不工作
<ams:fault xmlns:ams="http://wso2.org/apimanager/security"><ams:code>900902</ams:code><ams:message>Missing Credentials</ams:message><ams:description>Required OAuth credentials not provided. Make sure your API invocation call has a header: "Authorization: Bearer ACCESS_TOKEN"</ams:description></ams:fault>
var
LClient: TRESTClient;
LRequest: TRESTRequest;
LResponse: TRESTResponse;
begin
LClient := TRESTClient.Create('https://apigateway.serpro.gov.br/consulta-cnpj-
df/v1/cnpj/99999999999999');
try
LRequest := TRESTRequest.Create(LClient);
try
LResponse := TRESTResponse.Create(LClient);
try
LRequest.Client := LClient;
LRequest.Response := LResponse;
LRequest.Accept:='application/json';
LRequest.Params.AddHeader('Authorization', 'Bearer 6315a3c9c2e4bb2e0816da132828f269');
LRequest.Method := rmGET;
LRequest.Execute;
Memo1.Clear;
Memo1.Lines.Add(IntToStr(LResponse.StatusCode) + ' / ' + LResponse.StatusText);
Memo1.Lines.Add(LResponse.Headers.Text);
Memo1.Lines.Add('--------------------------------------------------------------');
Memo1.Lines.Add(LResponse.Content);
finally
LResponse.Free;
end;
finally
LRequest.Free;
end;
finally
LClient.Free;
end;
end;
有人可以帮助我吗?
Auth header 需要在不编码的情况下发送,所以使用 AddItem
而不是 AddHeader
LRequest.Params.AddItem ('Authorization', 'Bearer ' + YourToken, pkHTTPHEADER, [poDoNotEncode]);
Embarcadero REST 框架可能令人困惑。我也没有长时间使用 REST,所以我自己仍在努力。