5.27Setting the Referrer Address (Hotlink Protection)

Updated on Aug 20, 2026~3 min read

When accessing certain third-party servers, the server may validate the Referer source address in the request headers. For example, when downloading images, triggering the hotlink protection mechanism may cause the retrieved images to not match expectations. In this case, you can set the Referer request header to simulate the source page and bypass hotlink protection detection.

HTTP Declarative Requests set the request referrer address through the RefererAttribute attribute. The corresponding HTTP declarative extractor is implemented as the RefererDeclarativeExtractor type, which is responsible for parsing the RefererAttribute attribute and building the request referrer address configuration required by an HttpRequestBuilder instance.

cs
// Apply at the interface level to affect all methods[Referer("https://furion.net")]public interface IHttpService : IHttpDeclarative{    [Get("https://furion.net/logo.png")]    Task<string> GetStringAsync();    // Apply at the method level    [Referer("https://baiqian.com")]    [Get("https://furion.net/logo2.png")]    Task<string> GetStringAsync();}

Once enabled, the request referrer address is automatically set when sending HTTP remote requests.

To simplify configuration, the framework provides a built-in template string "{BASE_ADDRESS}" that automatically extracts the base address of the request address as the Referer:

cs
[Referer("{BASE_ADDRESS}")] // Automatically replaces {BASE_ADDRESS} with https://furion.net/ when sendingpublic interface IHttpService : IHttpDeclarative{    [Get("https://furion.net/logo.png")]    Task<string> GetStringAsync();}

RefererAttribute includes the following constructors and properties:

  • Constructors:

    • new(referer): Applies to methods or interfaces, setting the request referrer address.
  • Properties:

    • Referer: The request referrer address (type string).