Jump to content
alank2

TNetHTTPClient and custom header

Recommended Posts

I need to specify a custom header that they have a curl example for.

 

$ curl "https://examplesite"
-H 'Authorization: Token token=key1, btoken=key2'
-X GET

 

The documentation for the TNetHTTPClient says this - can I send the above "Authorization: Token token=key1, btoken=key2" as a custom header using the TNetHTTPClient component?  If so, how?

Sending a Request with Custom Headers

The HTTP client component and the HTTP request component both allow you to set custom headers. The custom headers that you can specify are:

When you execute a request, the THTTPClient.Execute method of the HTTP framework combines the custom headers from the HTTP client component and the corresponding HTTP request component and adds those headers to the final request.

Share this post


Link to post

Would it be:

 

NetHTTPClient1->CustomHeaders["Authorization"]=" Token token=key1, btoken=key2 ";

Share this post


Link to post
2 hours ago, alank2 said:

NetHTTPClient1->CustomHeaders["Authorization"]=" Token token=key1, btoken=key2 ";

Alternatively, these would probably work, too:

NetHTTPClient1->CustHeaders->Value["Authorization"] = "Token token=key1, btoken=key2";
NetHTTPClient1->CustHeaders->Add("Authorization", "Token token=key1, btoken=key2");
TNetHeaders AuthHeader;
AuthHeader.Length = 1;
AuthHeader[0] = TNameValuePair("Authorization", "Token token=key1, btoken=key2");
NetHTTPClient1->Get("https://examplesite", NULL, AuthHeader);

 

  • Like 1

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

×