procedure GetAPIData(Endpoint: Text; Header1Value: Text; Header2Value: Text) var HttpClient: HttpClient; HttpResponse: HttpResponseMessage; ResponseText: text; Uri: Text; Header1: Text; Header2: Text; begin //Uri := Endpoint + APIKey; Uri := Endpoint; if HttpClient.Get(Uri, HttpResponse) then // HttpResponse.Headers().Add(Header1, Header1Value); // HttpResponse.Headers().Add(Header2, Header2Value); if HttpResponse.IsSuccessStatusCode() then begin HttpResponse.Headers().Add(Header1, Header1Value); HttpResponse.Headers().Add(Header2, Header2Value); HttpResponse.Content().ReadAs(ResponseText); Message(ResponseText); end; end;
procedure GetAPIData(Endpoint: Text; Header1Value: Text; Header2Value: Text) var HttpClient: HttpClient; HttpResponse: HttpResponseMessage; HttpRequest: HttpRequestMessage; HttpHeader: HttpHeaders; ResponseText: Text; Header1: Label 'x-rapidapi-key', Locked = true; Header2: Label 'x-rapidapi-host', Locked = true; begin HttpHeader := HttpClient.DefaultRequestHeaders(); HttpHeader.Add(Header1, Header1Value); HttpHeader.Add(Header2, Header2Value); if HttpClient.Get(Endpoint, HttpResponse) then if HttpResponse.IsSuccessStatusCode() then begin HttpResponse.Content().ReadAs(ResponseText); Message(ResponseText); end; end;
Answers
Adding them to the response won't help that much I think.
And ofcourse, if you want to add headers, you must make sure they have a value.
You used Text variables, but they are empty and thus you get the error that the header parameter name is null or empty.
Haven't tried the code below, but might guide you in the right direction.
Tomorrow I could check further if needed.