Jump to content
ottojr

Parameter passing

Recommended Posts

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
  • 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

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

In HTTP headers, there is always a space after the colon, seems simple but sufficient to confuse servers.

 

Angus

 

  • Like 1

Share this post


Link to post

Thank you everyone for helping. It worked here! 🤜🤛  🤝

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×