ottojr 0 Posted April 19 Good afternoon people. How do I write in the head of the request to send a key as shown in the example below? I would like to thank you for any help. I'm trying like this: SslHttpRest.RestParams.AddItem('Store-Token', '123456789x'); Here I am using POSTMAN object(Slim\Http\Headers)#302 (1) { ["data":protected]=> array(9) { ["Content-Type"]=> string(16) "application/json" ["Content-Length"]=> string(0) "" ["Store-Token"]=> string(32) "22345673301244567896663456789012" ["User-Agent"]=> string(21) "PostmanRuntime/7.37.3" ["Accept"]=> string(3) "*/*" ["Postman-Token"]=> string(36) "40f28212-2f71-487a-a22f-d6ecdfa61b8b" ["Host"]=> string(14) "localhost:8080" ["Accept-Encoding"]=> string(17) "gzip, deflate, br" ["Connection"]=> string(10) "keep-alive" }} Here I am using the "TSslHttpRest" component and I need the key "["Store-Token"]" object(Slim\Http\Headers)#302 (1) { ["data":protected]=> array(7) { ["Content-Type"]=> string(16) "application/json" ["Content-Length"]=> string(0) "" ["Accept"]=> string(30) "application/json;charset=UTF-8" ["Connection"]=> string(10) "keep-alive" ["Accept-Encoding"]=> string(13) "gzip, deflate" ["User-Agent"]=> string(110) "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36" ["Host"]=> string(14) "localhost:8080" } } Share this post Link to post
Lars Fosdal 1792 Posted April 19 Which language Which version Which class is SslHttpRest, and from which unit? If you use System.Net.HttpClient (which I use, because getting the REST classes to work with various flavours of OAuth2 turned out to be a challenge), you can do it something like this (code is not complete 😞 var HTTPRequest: IHttpRequest; // from System.Net.HttpClient HttpResponse: IHttpResponse; // System.Net.HttpClient ReqHeaders: TNetHeaders; // System.Net.URLClient URL: String; begin try try try HTTPRequest := HTTP.GetRequest('GET', URL); ReqHeaders := [ TNetHeader.Create('Content-Type', 'application/json'), TNetHeader.Create('Content-Length, ''), TNetHeader.Create('Store-Token', '22345673301244567896663456789012'), TNetHeader.Create('User-Agent', 'PostmanRuntime/7.37.3'), TNetHeader.Create('Accept', '*/*'), TNetHeader.Create('Postman-Token', '40f28212-2f71-487a-a22f-d6ecdfa61b8b'), TNetHeader.Create('Host', 'localhost:8080'), TNetHeader.Create('Accept-Encoding', 'gzip, deflate, br'), TNetHeader.Create('Connection', 'keep-alive') ]; HttpResponse := HTTP.Execute(HTTPRequest,nil, ReqHeaders); // HTTP is THTTPClient from System.Net.HttpClient ... Share this post Link to post
Angus Robertson 574 Posted April 19 TSslHttpRest is an ICS component, and to add a special header field you use the component ExtraHeaders: Strings property to add the full header and value, ie ExtraHeaders.Add('Store-Token: 22345673301244567896663456789012'); Angus Share this post Link to post
ottojr 0 Posted April 19 I'm using Delphi 10.3 I am sharing the source code as an attachment Robertson, i try ExtraHeaders.Add, but it did not work procedure TSnippets.doHttpRestReqCl.txt Share this post Link to post
Angus Robertson 574 Posted April 19 In HTTP headers, there is always a space after the colon, seems simple but sufficient to confuse servers. Angus 1 Share this post Link to post
ottojr 0 Posted April 19 Thank you everyone for helping. It worked here! 🤜🤛 🤝 Share this post Link to post