Hello!
I have a problem with a GET query.
POST queries work without any problem while GET has an authorization error. My code:
procedure GetProductInfo(_ItemId: Integer; _Token: Text) var Client: HttpClient; Request: HttpRequestMessage; Response: HttpResponseMessage; Headers: HttpHeaders; Uri: Text; FullToken: Text; ResponseTxt: Text; Json: JsonObject; begin Uri := 'https://myaddress.com/product/' Format(_ItemId); FullToken := 'Bearer ' Format(_Token); Request.Method := 'GET'; Request.SetRequestUri(Uri); Headers.Add('Authorization', FullToken); Request.GetHeaders(Headers); Client.Send(Request, Response); if Response.IsSuccessStatusCode() then begin Response.Content.ReadAs(ResponseTxt); Json.ReadFrom(ResponseTxt); ProductId := GetJsonTextField(Json, 'product_id'); ProductCode := GetJsonTextField(Json, 'code'); Evaluate(Stock, GetJsonTextField(Json, 'stock')); Message('Good'); end else Message('Bad'); end;
Error: HTTP 401
Everything works fine in Postman.
Best Regards
Great.
Thank you for response! I changed
Headers.Add('Authorization', FullToken);
to
Client.DefaultRequestHeaders.Add('Authorization', FullToken);
Problem solved!
Hi,
Please try this
http_Content.GetHeaders(http_Header);
http_Header.Clear();
http_Client.DefaultRequestHeaders.Add('Authorization', 'Bearer ' + APIKey + '');
http_Header.Add('Content-Type', 'application/json');
if http_Client.get(APIURL, httpResMsg) then
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,151 Super User 2024 Season 2
Martin Dráb 229,963 Most Valuable Professional
nmaenpaa 101,156