Search code examples
delphihttp-headersrequest-headerstmstms-web-core

How do I add my own custom header key/value on TWebHttpRequest?


I've placed a non-visual TWebHttpRequest component onto my form and there is a Headers property where I can see and change some of the default headers:

TWebHttpRequest Headers in Delphi

But there doesn't seem to be a way to add my own custom header key/value to it.

This link shows a String List Editor for Headers, but I don't seem to have that on my side: enter image description here

This is what I have on my side: enter image description here

How would I go about adding my own custom Headers?


Solution

  • You can add custom headers during run-time using WebHttpRequest.Headers.AddPair like this:

    WebHttpRequest.Headers.Clear;
    
    WebHttpRequest.Headers.AddPair('custom-header','whatever');
    WebHttpRequest.Headers.AddPair('Content-Type','application/json');
    

    I haven't figured out how to add custom headers during design-time yet though. Maybe someone else can answer that.