Explicit Credentials for a .NET WebProxy
Assign credentials explicitly when constructing a .NET WebProxy instead of assuming a credential-bearing URI populates its account.
A URI can contain username:password before its host. That does not mean every .NET API accepting that URI copies the user info into an authentication object.
When constructing WebProxy directly, make the credential assignment explicit:
var proxy = new WebProxy("http://203.0.113.10:8080")
{
Credentials = new NetworkCredential(proxyUser, proxyPassword)
};The endpoint and account variables are illustrative. This keeps the destination address, proxy address, and proxy account separate.
If an input format supplies a credential-bearing URL, parse its user info deliberately. Preserve a password containing colons by splitting only at the credential separator, and decode encoded components at the appropriate stage. Avoid printing the original URL while diagnosing that parser.
A proxy URL working as an environment setting can still behave differently when passed into a different constructor. Environment-proxy initialization has its own parsing logic; it is not a promise that every constructor consumes the same fields.
Finally, set the configured proxy object on the handler that performs the request. Correct credentials on an unused WebProxy cannot affect the connection.