I'm sending HTTP GET Request to my API with custom Header
var request = new RestRequest(endpoint, Method.GET);
request.AddHeader("__Test", data);
var response = client.Execute(request);
Everything works fine on localhost, but when I deploy API on server which is using Nginx then this header is "lost"
That's my nginx config
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
Startup.cs
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
app.UseHttpsRedirection();
This works fine on localhost, but not on server:
HttpContext.Request.Headers.TryGetValue("__Test", out var data)
Anybody has an idea what can go wrong?
Problem occured because I used __ in header's name
Solution:
Use
underscores_in_headers on;
in
nginx.conf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With