dotnet / dotnet/dotnet-api-docs

Document ProductInfoHeaderValue constructors

Open
#3,274 2 comments 5 reactions 0 assignees View on GitHub
area-System.Net doc-enhancement help wanted Pri3
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

I'm sometimes making HTTP requests to various APIs. Quite often, they require specifying [the User-Agent header](https://en.wikipedia.org/wiki/User_agent#Use_in_HTTP). To do that with `HttpClient`, I have to create `ProductInfoHeaderValue`, e.g.:

```c#
ProductInfoHeaderValue value = …;
var client = new HttpClient { DefaultRequestHeaders = { UserAgent = { value } } };
```

My problem is that creating valid `ProductInfoHeaderValue` is not obvious and [the documentation for its constructors](https://docs.microsoft.com/en-us/dotnet/api/system.net.http.headers.productinfoheadervalue.-ctor) does not explain which constructor I should use or what are the requirements for the `string` parameters.

As an example, if I try `new ProductInfoHeaderValue("svick's awesome tool")`, it throws "FormatException: The format of value 'svick's awesome tool' is invalid." This doesn't help me figure out what the valid values are, which is why I think documenting this is important.

[This article](http://bizcoder.com/the-much-maligned-user-agent-header) explains the rules for User-Agent values and might be helpful when resolving this issue.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.