C
C#2y ago
JohnP55

❔ So I'm writing an API for a game in C#, and I need the User-Agent to be an empty string.

The dev isn't exactly good at security, and long story short, in order to properly send a request, the User-Agent must be set to an empty string. However, using System.Net.Http, I have been unable to find a way to specifically make it an empty string rather than simply non-existent. To clarify, it must actually exist in the request, but be empty. Is this even possible using System.net.Http?
10 Replies
Angius
Angius2y ago
client.DefaultRequestHeaders.Add("User-Agent", "");
client.DefaultRequestHeaders.Add("User-Agent", "");
doesn't work?
JohnP55
JohnP55OP2y ago
It doesn't:
Unhandled exception. System.FormatException: The format of value '' is invalid.
at System.Net.Http.Headers.HttpHeaderParser.ParseValue(String value, Object storeValue, Int32& index)
at System.Net.Http.Headers.HttpHeaders.ParseAndAddValue(HeaderDescriptor descriptor, HeaderStoreItemInfo info, String value)
at System.Net.Http.Headers.HttpHeaders.Add(HeaderDescriptor descriptor, String value)
at System.Net.Http.Headers.HttpHeaders.Add(String name, String value)
Unhandled exception. System.FormatException: The format of value '' is invalid.
at System.Net.Http.Headers.HttpHeaderParser.ParseValue(String value, Object storeValue, Int32& index)
at System.Net.Http.Headers.HttpHeaders.ParseAndAddValue(HeaderDescriptor descriptor, HeaderStoreItemInfo info, String value)
at System.Net.Http.Headers.HttpHeaders.Add(HeaderDescriptor descriptor, String value)
at System.Net.Http.Headers.HttpHeaders.Add(String name, String value)
it's like it specifically doesn't let you do that
Angius
Angius2y ago
huh
client.DefaultRequestHeaders.Add("User-Agent", null);
client.DefaultRequestHeaders.Add("User-Agent", null);
?
JohnP55
JohnP55OP2y ago
getting CS0121 because it's ambiguous between the call with HttpHeaders.Add(string, IEnumerable<string?>) and HttpHeaders.Add(string, string?) and yea if I try anything else then the format of <null> is also invalid
Angius
Angius2y ago
client.DefaultRequestHeaders.Add("User-Agent", (string?)null);
client.DefaultRequestHeaders.Add("User-Agent", (string?)null);
? The docs only say the format exception will be thrown if the name of the header is incorrect Says nothing about the value of it
JohnP55
JohnP55OP2y ago
yea that's what I did for null
Unhandled exception. System.FormatException: The format of value '<null>' is invalid.
at System.Net.Http.Headers.HttpHeaderParser.ParseValue(String value, Object storeValue, Int32& index)
at System.Net.Http.Headers.HttpHeaders.ParseAndAddValue(HeaderDescriptor descriptor, HeaderStoreItemInfo info, String value)
at System.Net.Http.Headers.HttpHeaders.Add(HeaderDescriptor descriptor, String value)
at System.Net.Http.Headers.HttpHeaders.Add(String name, String value)
Unhandled exception. System.FormatException: The format of value '<null>' is invalid.
at System.Net.Http.Headers.HttpHeaderParser.ParseValue(String value, Object storeValue, Int32& index)
at System.Net.Http.Headers.HttpHeaders.ParseAndAddValue(HeaderDescriptor descriptor, HeaderStoreItemInfo info, String value)
at System.Net.Http.Headers.HttpHeaders.Add(HeaderDescriptor descriptor, String value)
at System.Net.Http.Headers.HttpHeaders.Add(String name, String value)
Angius
Angius2y ago
There's .TryAddWithoutValidation() Maybe this one?
JohnP55
JohnP55OP2y ago
I guess that one worked
JohnP55
JohnP55OP2y ago
Still getting Cloudflare error code 1020, so there's something left I'll have to look into Yep I got it to work now thank you so much for the help
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server