Thursday, April 25, 2019

Easily craft complicated URL line variables in C# while encoding both colons to %3a and forward slashes to %2f as well.

var nameValueCollection = new NameValueCollection
{
   {"response_type", "code"},
   {"client_id", "1d097a7f-f773-464c-b24e-6b904a19861a"},
   {"resource", "https://analysis.windows.net/powerbi/api"},
   {"redirect_uri", "http://www.example.com/"}
};
var queryString = HttpUtility.ParseQueryString(string.Empty);
queryString.Add(nameValueCollection);
string whereTo = "https://login.windows.net/common/oauth2/authorize/";
whereTo = String.Format("{0}?{1}", whereTo, queryString);

No comments:

Post a Comment