Here are the examples of the csharp api System.Net.WebUtility.UrlEncode(string) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
538 Examples
19
View Source File : ArticleListViewModelBase.cs
License : MIT License
Project Creator : weeklyxamarin
License : MIT License
Project Creator : weeklyxamarin
private void ExecuteCategorySearch(Article article)
{
navigation.GoToAsync(Constants.Navigation.Paths.Search, Constants.Navigation.ParameterNames.Category, WebUtility.UrlEncode(article.Category));
}
19
View Source File : HttpHelper.cs
License : MIT License
Project Creator : WeihanLi
License : MIT License
Project Creator : WeihanLi
public static Task<string> HttpPostAsync(string url, IDictionary<string, string>? parameters)
=> HttpPostAsync(url,
Encoding.UTF8.GetBytes(string.Join("&",
parameters?.Select(p => $"{WebUtility.UrlEncode(p.Key)}={WebUtility.UrlEncode(p.Value)}") ?? Array.Empty<string>())), false);
19
View Source File : HttpHelper.cs
License : MIT License
Project Creator : WeihanLi
License : MIT License
Project Creator : WeihanLi
public static async Task<string> HttpGetStringAsync(string url, IDictionary<string, string>? parameters)
{
if (parameters != null && parameters.Count > 0)
{
url = url + (url.IndexOf('?') < 0 ? "?" : "&") + string.Join("&", parameters.Select(p => $"{WebUtility.UrlEncode(p.Key)}={WebUtility.UrlEncode(p.Value)}"));
}
return await HttpGetStringAsync(url);
}
19
View Source File : HttpHelper.cs
License : MIT License
Project Creator : WeihanLi
License : MIT License
Project Creator : WeihanLi
public static string HttpPost(string url, IDictionary<string, string>? parameters)
=> HttpPost(url,
Encoding.UTF8.GetBytes(string.Join("&",
parameters?.Select(p => $"{WebUtility.UrlEncode(p.Key)}={WebUtility.UrlEncode(p.Value)}") ?? Array.Empty<string>())), false);
19
View Source File : HttpHelper.cs
License : MIT License
Project Creator : WeihanLi
License : MIT License
Project Creator : WeihanLi
public static string HttpGetString(string url, IDictionary<string, string>? parameters)
{
if (parameters != null && parameters.Count > 0)
{
url = url + (url.IndexOf('?') < 0 ? "?" : "&") + string.Join("&", parameters.Select(p => $"{WebUtility.UrlEncode(p.Key)}={WebUtility.UrlEncode(p.Value)}"));
}
return HttpGetString(url);
}
19
View Source File : UriHelper.cs
License : MIT License
Project Creator : Whinarn
License : MIT License
Project Creator : Whinarn
public static string UrlEncodeText(string text)
{
if (text == null)
throw new ArgumentNullException("text");
else if (text.Length == 0)
return string.Empty;
return WebUtility.UrlEncode(text);
}
19
View Source File : WebPageRequestInfo.cs
License : MIT License
Project Creator : WilliamABradley
License : MIT License
Project Creator : WilliamABradley
private string ToQueryString(List<KeyValuePair<string, string>> collection)
{
var querypairs = collection
.Select(item =>
string.Format($"{WebUtility.UrlEncode(item.Key)}={WebUtility.UrlEncode(item.Value)}"));
return "?" + string.Join("&", querypairs);
}
19
View Source File : ExternalCommand.cs
License : GNU General Public License v3.0
Project Creator : wmjordan
License : GNU General Public License v3.0
Project Creator : wmjordan
public static void OpenWithWebBrowser(string url, string text) {
ThreadHelper.ThrowIfNotOnUIThread();
try {
url = url.Replace("%s", System.Net.WebUtility.UrlEncode(text));
if (Keyboard.Modifiers == ModifierKeys.Control) {
CodistPackage.DTE.ItemOperations.Navigate(url);
}
else if (String.IsNullOrEmpty(Config.Instance.BrowserPath) == false) {
System.Diagnostics.Process.Start(Config.Instance.BrowserPath, String.IsNullOrEmpty(Config.Instance.BrowserParameter) ? url : Config.Instance.BrowserParameter.Replace("%u", url));
}
else {
System.Diagnostics.Process.Start(url);
}
}
catch (Exception ex) {
MessageBox.Show(R.T_FailedToLaunchBrowser + Environment.NewLine + ex.Message, nameof(Codist), MessageBoxButton.OK, MessageBoxImage.Exclamation);
}
}
19
View Source File : YandexDiskCloud.cs
License : MIT License
Project Creator : worldbeater
License : MIT License
Project Creator : worldbeater
public async Task DownloadFile(string from, Stream to)
{
var yaPath = from.Replace("\\", "/");
var encodedPath = WebUtility.UrlEncode(yaPath);
var pathUrl = ApiDownloadFileUrl + encodedPath;
using var response = await _http.GetAsync(pathUrl).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
var json = await response.Content.ReadreplacedtringAsync().ConfigureAwait(false);
var content = JsonConvert.DeserializeObject<YandexFileLoadResponse>(json);
using (var file = await _http.GetAsync(content.Href).ConfigureAwait(false))
using (var stream = await file.Content.ReadreplacedtreamAsync().ConfigureAwait(false))
await stream.CopyToAsync(to).ConfigureAwait(false);
await to.FlushAsync().ConfigureAwait(false);
to.Close();
}
19
View Source File : YandexDiskCloud.cs
License : MIT License
Project Creator : worldbeater
License : MIT License
Project Creator : worldbeater
public async Task CreateFolder(string path, string name)
{
var directory = Path.Combine(path, name).Replace("\\", "/");
var encoded = WebUtility.UrlEncode(directory);
var pathUrl = ApiGetPathBase + encoded;
using var response = await _http.PutAsync(pathUrl, null).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
}
19
View Source File : YandexDiskCloud.cs
License : MIT License
Project Creator : worldbeater
License : MIT License
Project Creator : worldbeater
public async Task RenameFile(string path, string name)
{
var directoryName = Path.GetDirectoryName(path);
var fromPath = WebUtility.UrlEncode(path);
var toPath = Path.Combine(directoryName, name);
var pathUrl = $"{ApiMoveFileUrl}?from={fromPath}&path={toPath}";
using var response = await _http.PostAsync(pathUrl, null).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
}
19
View Source File : YandexDiskCloud.cs
License : MIT License
Project Creator : worldbeater
License : MIT License
Project Creator : worldbeater
public async Task UploadFile(string to, Stream from, string name)
{
var yaPath = Path.Combine(to, name).Replace("\\", "/");
var encodedPath = WebUtility.UrlEncode(yaPath);
var pathUrl = ApiUploadFileUrl + encodedPath;
using var response = await _http.GetAsync(pathUrl).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
var json = await response.Content.ReadreplacedtringAsync().ConfigureAwait(false);
var content = JsonConvert.DeserializeObject<YandexFileLoadResponse>(json);
var httpContent = new StreamContent(@from);
using var file = await _http.PutAsync(content.Href, httpContent).ConfigureAwait(false);
file.EnsureSuccessStatusCode();
}
19
View Source File : YandexDiskCloud.cs
License : MIT License
Project Creator : worldbeater
License : MIT License
Project Creator : worldbeater
public async Task<IEnumerable<FileModel>> GetFiles(string path)
{
var yaPath = path.Replace("\\", "/");
var encodedPath = WebUtility.UrlEncode(yaPath);
var pathUrl = ApiGetPathBase + encodedPath;
using var response = await _http.GetAsync(pathUrl).ConfigureAwait(false);
var json = await response.Content.ReadreplacedtringAsync().ConfigureAwait(false);
response.EnsureSuccessStatusCode();
var content = JsonConvert.DeserializeObject<YandexContentResponse>(json);
return content.Embedded.Items.Select(file => new FileModel
{
Name = file.Name,
IsFolder = file.Type == "dir",
Path = file.Path.Replace("disk:", string.Empty),
Modified = file.Created,
Size = file.Size
});
}
19
View Source File : YandexDiskCloud.cs
License : MIT License
Project Creator : worldbeater
License : MIT License
Project Creator : worldbeater
public async Task Delete(string path, bool isFolder)
{
var encodedPath = WebUtility.UrlEncode(path);
var pathUrl = ApiGetPathBase + encodedPath;
using var response = await _http.DeleteAsync(pathUrl).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
}
19
View Source File : Download.cs
License : MIT License
Project Creator : Wyamio
License : MIT License
Project Creator : Wyamio
private Uri ApplyQueryString(Uri uri, IDictionary<string, string> queryString)
{
UriBuilder builder = new UriBuilder(uri);
if (queryString.Count > 0)
{
string query = builder.Query;
if (string.IsNullOrEmpty(query))
{
query = "?";
}
else
{
query = query + "&";
}
query = query
+ string.Join(
"&",
queryString.Select(x => string.IsNullOrEmpty(x.Value)
? WebUtility.UrlEncode(x.Key)
: $"{WebUtility.UrlEncode(x.Key)}={WebUtility.UrlEncode(x.Value)}"));
builder.Query = query;
}
return builder.Uri;
}
19
View Source File : Embed.cs
License : MIT License
Project Creator : Wyamio
License : MIT License
Project Creator : Wyamio
protected IShortcodeResult Execute(string endpoint, string url, IEnumerable<string> query, IExecutionContext context)
{
// Get the oEmbed response
EmbedResponse embedResponse;
using (HttpClient httpClient = context.CreateHttpClient())
{
string request = $"{endpoint}?url={WebUtility.UrlEncode(url)}";
if (query != null)
{
request += "&" + string.Join("&", query);
}
HttpResponseMessage response = httpClient.GetAsync(request).Result;
if (response.StatusCode == HttpStatusCode.NotFound)
{
Trace.Error($"Received 404 not found for oEmbed at {request}");
}
response.EnsureSuccessStatusCode();
if (response.Content.Headers.ContentType.MediaType == "application/json"
|| response.Content.Headers.ContentType.MediaType == "text/html")
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(EmbedResponse));
using (Stream stream = response.Content.ReadreplacedtreamAsync().Result)
{
embedResponse = (EmbedResponse)serializer.ReadObject(stream);
}
}
else if (response.Content.Headers.ContentType.MediaType == "text/xml")
{
DataContractSerializer serializer = new DataContractSerializer(typeof(EmbedResponse));
using (Stream stream = response.Content.ReadreplacedtreamAsync().Result)
{
embedResponse = (EmbedResponse)serializer.ReadObject(stream);
}
}
else
{
throw new InvalidDataException("Unknown content type for oEmbed response");
}
}
// Switch based on type
if (!string.IsNullOrEmpty(embedResponse.Html))
{
return context.GetShortcodeResult(embedResponse.Html);
}
else if (embedResponse.Type == "photo")
{
if (string.IsNullOrEmpty(embedResponse.Url)
|| string.IsNullOrEmpty(embedResponse.Width)
|| string.IsNullOrEmpty(embedResponse.Height))
{
throw new InvalidDataException("Did not receive required oEmbed values for image type");
}
return context.GetShortcodeResult($"<img src=\"{embedResponse.Url}\" width=\"{embedResponse.Width}\" height=\"{embedResponse.Height}\" />");
}
else if (embedResponse.Type == "link")
{
if (!string.IsNullOrEmpty(embedResponse.replacedle))
{
return context.GetShortcodeResult($"<a href=\"{url}\">{embedResponse.replacedle}</a>");
}
return context.GetShortcodeResult($"<a href=\"{url}\">{url}</a>");
}
throw new InvalidDataException("Could not determine embedded content for oEmbed response");
}
19
View Source File : HttpClientExtensions.cs
License : MIT License
Project Creator : xfrogcn
License : MIT License
Project Creator : xfrogcn
public static async Task<TResponse> SubmitFormAsync<TResponse>(this HttpClient client, string url, Dictionary<string, string> formData, string method = "POST", NameValueCollection queryString = null, NameValueCollection headers = null, bool ignoreEncode = false)
{
url = CreateUrl(url, queryString);
HttpMethod hm = new HttpMethod(method);
HttpRequestMessage request = new HttpRequestMessage(hm, url);
if (ignoreEncode)
{
StringBuilder sb = new StringBuilder();
if (formData != null)
{
foreach (var kv in formData)
{
if (sb.Length > 0)
{
sb.Append("&");
}
sb.Append(kv.Key).Append("=");
sb.Append(WebUtility.UrlEncode(kv.Value ?? ""));
}
}
request.Content = new StringContent(sb.ToString());
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
}
else
{
// 可能引发异常 System.UriFormatException : Invalid URI: The Uri string is too long.
request.Content = new FormUrlEncodedContent(formData);
}
MergeHttpHeaders(request, headers);
var response = await client.SendAsync(request);
if (!request.IsDisableEnsureSuccessStatusCode())
{
response.EnsureSuccessStatusCode();
}
return await response.GetObjectAsync<TResponse>();
}
19
View Source File : HttpClientExtensions.cs
License : MIT License
Project Creator : xfrogcn
License : MIT License
Project Creator : xfrogcn
public static async Task<TResponse> UploadStreamAsync<TResponse>(
this HttpClient client,
string url,
string partKey,
Stream fileStream,
string fileName,
string fileMediaType = null,
string boundary = null,
Dictionary<string, string> formData = null,
string method = "POST",
NameValueCollection queryString = null,
NameValueCollection headers = null)
{
if (string.IsNullOrEmpty(boundary))
{
boundary = $"--------------------------{DateTime.Now.Ticks}";
}
if (string.IsNullOrEmpty(partKey))
{
partKey = "\"\"";
}
else
{
partKey = $"\"{partKey}\"";
}
url = CreateUrl(url, queryString);
HttpMethod hm = new HttpMethod(method);
HttpRequestMessage request = new HttpRequestMessage(hm, url);
var content = new MultipartFormDataContent(boundary);
content.Headers.ContentType = new MediaTypeHeaderValue("multipart/form-data");
content.Headers.ContentType.Parameters.Add(new NameValueHeaderValue("boundary", boundary));
if (formData != null)
{
foreach (var kv in formData)
{
content.Add(new StringContent(kv.Value), kv.Key);
}
}
StreamContent fileContent = new StreamContent(fileStream);
fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
{
Name = partKey,
};
// 跨平台兼容
fileContent.Headers.ContentDisposition.Parameters.Add(new NameValueHeaderValue("filename", $"\"{WebUtility.UrlEncode(fileName)}\""));
fileContent.Headers.ContentDisposition.Parameters.Add(new NameValueHeaderValue("filename*", $"\"UTF-8''{WebUtility.UrlEncode(fileName)}\""));
if (!string.IsNullOrEmpty(fileMediaType))
{
fileContent.Headers.ContentType = new MediaTypeHeaderValue(fileMediaType);
}
content.Add(fileContent);
request.Content = content;
MergeHttpHeaders(request, headers);
var response = await client.SendAsync(request);
if (!request.IsDisableEnsureSuccessStatusCode())
{
response.EnsureSuccessStatusCode();
}
return await response.GetObjectAsync<TResponse>();
}
19
View Source File : HttpClientExtensions.cs
License : MIT License
Project Creator : xfrogcn
License : MIT License
Project Creator : xfrogcn
public static string CreateUrl(string url, NameValueCollection qs)
{
if (qs != null && qs.Count > 0)
{
StringBuilder sb = new StringBuilder();
List<string> kl = qs.AllKeys.ToList();
foreach (string k in kl)
{
if (sb.Length > 0)
{
sb.Append("&");
}
sb.Append(k).Append("=");
if (!String.IsNullOrEmpty(qs[k]))
{
sb.Append(System.Net.WebUtility.UrlEncode(qs[k]));
}
}
if (url.Contains("?"))
{
url = url + "&" + sb.ToString();
}
else
{
url = url + "?" + sb.ToString();
}
}
return url;
}
19
View Source File : SetTokenProcessor.cs
License : MIT License
Project Creator : xfrogcn
License : MIT License
Project Creator : xfrogcn
public override Task SetTokenAsync(HttpRequestMessage request, string token)
{
UriBuilder ub = new UriBuilder(request.RequestUri);
var qs = System.Web.HttpUtility.ParseQueryString(request.RequestUri.Query);
qs[_queryKey] = token;
StringBuilder sb = new StringBuilder();
var kl = qs.AllKeys;
foreach (string k in kl)
{
if (sb.Length > 0)
{
sb.Append("&");
}
sb.Append(k).Append("=");
if (!String.IsNullOrEmpty(qs[k]))
{
sb.Append(System.Net.WebUtility.UrlEncode(qs[k]));
}
}
ub.Query = sb.ToString();
request.RequestUri = ub.Uri;
return Task.CompletedTask;
}
19
View Source File : AlipayAppService.cs
License : GNU General Public License v3.0
Project Creator : xin-lai
License : GNU General Public License v3.0
Project Creator : xin-lai
public Task<AppPayOutput> AppPay(AppPayInput input)
{
var client = GetClient();
var request = new AlipayTradeAppPayRequest();
var model = new AlipayTradeAppPayModel
{
Body = input.Body,
DisablePayChannels = input.DisablePayChannels,
EnablePayChannels = input.EnablePayChannels,
//ExtendParams = input.ex
GoodsType = input.GoodsType,
OutTradeNo = input.TradeNo ?? Guid.NewGuid().ToString("N"),
PreplacedbackParams = WebUtility.UrlEncode(input.PreplacedbackParams),
ProductCode = "QUICK_MSECURITY_PAY",
PromoParams = input.PromoParams,
//SpecifiedChannel
StoreId = input.StoreId,
Subject = input.Subject,
TimeoutExpress = input.TimeoutExpress,
TotalAmount = input.TotalAmount.ToString()
};
request.SetBizModel(model);
request.SetNotifyUrl(input.NotifyUrl ?? _alipaySettings.Notify);
var response = client.SdkExecute(request);
if (response.IsError)
{
LoggerAction?.Invoke("Error", "支付宝支付请求参数错误:" + JsonConvert.SerializeObject(model));
throw new AlipayExcetion("支付宝支付请求参数错误,请检查!");
}
return Task.FromResult(new AppPayOutput
{
Response = response
});
}
19
View Source File : AlipayAppService.cs
License : GNU General Public License v3.0
Project Creator : xin-lai
License : GNU General Public License v3.0
Project Creator : xin-lai
public Task<WapPayOutput> WapPay(WapPayInput input)
{
var client = GetClient();
var request = new AlipayTradeWapPayRequest();
var model = new AlipayTradeWapPayModel
{
Body = input.Body,
DisablePayChannels = input.DisablePayChannels,
EnablePayChannels = input.EnablePayChannels,
//ExtendParams = input.ex
GoodsType = input.GoodsType,
OutTradeNo = input.TradeNo ?? Guid.NewGuid().ToString("N"),
PreplacedbackParams = WebUtility.UrlEncode(input.PreplacedbackParams),
ProductCode = "QUICK_WAP_WAY",
PromoParams = input.PromoParams,
//SpecifiedChannel
StoreId = input.StoreId,
Subject = input.Subject,
TimeoutExpress = input.TimeoutExpress,
TotalAmount = input.TotalAmount.ToString(CultureInfo.InvariantCulture),
QuitUrl = input.QuitUrl
};
request.SetBizModel(model);
request.SetNotifyUrl(input.NotifyUrl ?? _alipaySettings.Notify);
var response = client.pageExecute(request);
if (response.IsError)
{
LoggerAction?.Invoke("Error", "支付宝支付请求参数错误:" + JsonConvert.SerializeObject(model));
throw new AlipayExcetion("支付宝支付请求参数错误,请检查!");
}
return Task.FromResult(new WapPayOutput
{
Body = response.Body
});
}
19
View Source File : UserManage.cs
License : MIT License
Project Creator : xiaoyaocz
License : MIT License
Project Creator : xiaoyaocz
public static async Task<string> LoginBilibili(string UserName, string Preplacedword)
{
try
{
//https://api.bilibili.com/login?appkey=422fd9d7289a1dd9&platform=wp&pwd=JPJclVQpH4jwouRcSnngNnuPEq1S1rizxVJjLTg%2FtdqkKOizeIjS4CeRZsQg4%2F500Oye7IP4gWXhCRfHT6pDrboBNNkYywcrAhbOPtdx35ETcPfbjXNGSxteVDXw9Xq1ng0pcP1burNnAYtNRSayEKC1jiugi1LKyWbXpYE6VaM%3D&type=json&userid=xiaoyaocz&sign=74e4c872ec7b9d83d3a8a714e7e3b4b3
//发送第一次请求,得到access_key
string url = "https://api.bilibili.com/login?appkey=422fd9d7289a1dd9&platform=wp&pwd=" + WebUtility.UrlEncode(await GetEncryptedPreplacedword(Preplacedword)) + "&type=json&userid=" + WebUtility.UrlEncode(UserName);
url += "&sign=" + ApiHelper.GetSign(url);
string results = await WebClientClreplaced.GetResults(new Uri(url));
//Json解析及数据判断
LoginModel model = new LoginModel();
model = JsonConvert.DeserializeObject<LoginModel>(results);
if (model.code == -627)
{
return "登录失败,密码错误!";
}
if (model.code == -626)
{
return "登录失败,账号不存在!";
}
if (model.code == -625)
{
return "密码错误多次";
}
if (model.code == -628)
{
return "未知错误";
}
if (model.code == -1)
{
return "登录失败,程序注册失败!请联系作者!";
}
Windows.Web.Http.HttpClient hc = new Windows.Web.Http.HttpClient();
if (model.code == 0)
{
access_key = model.access_key;
Windows.Web.Http.HttpResponseMessage hr2 = await hc.GetAsync(new Uri("http://api.bilibili.com/login/sso?&access_key=" + model.access_key + "&appkey=422fd9d7289a1dd9&platform=wp"));
hr2.EnsureSuccessStatusCode();
SettingHelper.Set_Access_key(model.access_key);
}
//看看存不存在Cookie
HttpBaseProtocolFilter hb = new HttpBaseProtocolFilter();
HttpCookieCollection cookieCollection = hb.CookieManager.GetCookies(new Uri("http://bilibili.com/"));
List<string> ls = new List<string>();
foreach (HttpCookie item in cookieCollection)
{
ls.Add(item.Name);
}
if (ls.Contains("DedeUserID"))
{
return "登录成功";
}
else
{
return "登录失败";
}
}
catch (Exception ex)
{
if (ex.HResult == -2147012867)
{
return "登录失败,检查你的网络连接!";
}
else
{
return "登录发生错误";
}
}
}
19
View Source File : WebModule.cs
License : BSD 2-Clause "Simplified" License
Project Creator : xoofx
License : BSD 2-Clause "Simplified" License
Project Creator : xoofx
[KalkExport("url_encode", CategoryWeb)]
public string UrlEncode(string url) => WebUtility.UrlEncode(url);
19
View Source File : BiliApi.cs
License : GNU General Public License v3.0
Project Creator : xuan25
License : GNU General Public License v3.0
Project Creator : xuan25
private static string BuildQuery(List<KeyValuePair<string, string>> payload, bool sign)
{
if (payload == null)
{
payload = new List<KeyValuePair<string, string>>();
}
if (sign)
{
payload = SignPayload(payload);
}
StringBuilder stringBuilder = new StringBuilder();
foreach (KeyValuePair<string, string> item in payload)
{
stringBuilder.Append("&");
stringBuilder.Append(item.Key);
stringBuilder.Append("=");
stringBuilder.Append(WebUtility.UrlEncode(item.Value));
}
if (stringBuilder.Length == 0)
{
return string.Empty;
}
return stringBuilder.ToString().Substring(1);
}
19
View Source File : MastodonClient.cs
License : MIT License
Project Creator : yamachu
License : MIT License
Project Creator : yamachu
public static string ToUrlFormattedQueryString(this KeyValuePair<string, object> kvp)
{
if (kvp.Value == null || string.IsNullOrWhiteSpace(kvp.Value.ToString()))
{
return "";
}
if (kvp.Value is IEnumerable<int>)
{
return ((IEnumerable<int>)kvp.Value)
.Select(i => $"{kvp.Key}[]={i}")
.Aggregate((x, y) => $"{x}&{y}");
}
if (kvp.Value is Boolean)
{
return $"{kvp.Key}={System.Net.WebUtility.UrlEncode(kvp.Value.ToString().ToLower())}";
}
return $"{kvp.Key}={System.Net.WebUtility.UrlEncode(kvp.Value.ToString())}";
}
19
View Source File : DMEagleGet.cs
License : GNU General Public License v3.0
Project Creator : yhnmj6666
License : GNU General Public License v3.0
Project Creator : yhnmj6666
public void Fire()
{
Process eg = new Process();
eg.StartInfo.FileName = ExecutablePath;
eg.StartInfo.Arguments = string.Format(@"\S\U{0}&EGet_fname={1}U\ \C{2}C\ \R{3}R\", Url, System.Net.WebUtility.UrlEncode(FileName), Cookie, Refer);
if (Method == HttpMethod.POST)
eg.StartInfo.Arguments += string.Format(@" \P{0}P\", PostData.ToString());
eg.Start();
}
19
View Source File : PostInfo.cs
License : GNU General Public License v3.0
Project Creator : yhnmj6666
License : GNU General Public License v3.0
Project Creator : yhnmj6666
public override string ToString()
{
return Data==null?string.Empty:string.Join("&", Data.Select(item => string.Format("{0}={1}", item.Key, System.Net.WebUtility.UrlEncode(item.Value))));
}
19
View Source File : ConfigEncoder.cs
License : GNU General Public License v3.0
Project Creator : YtFlow
License : GNU General Public License v3.0
Project Creator : YtFlow
private static string ShadowsocksConfigEncoder(ShadowsocksConfig config)
{
var tag = string.Empty;
var parts = $"{config.Method}:{config.Preplacedword}";
var base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(parts));
var websafeBase64 = base64.Replace('+', '-').Replace('/', '_').TrimEnd('=');
var plugin = string.Empty; // Reserve for future
if (!string.IsNullOrWhiteSpace(plugin))
{
plugin = "?plugin=" + WebUtility.UrlEncode(plugin);
}
var url = $"{websafeBase64}@{config.ServerHost}:{config.ServerPort}/{plugin}";
if (!string.IsNullOrEmpty(config.Name))
{
tag = $"#{WebUtility.UrlEncode(config.Name)}";
}
return $"ss://{url}{tag}";
}
19
View Source File : ConfigEncoder.cs
License : GNU General Public License v3.0
Project Creator : YtFlow
License : GNU General Public License v3.0
Project Creator : YtFlow
private static string ShadowsocksConfigEncoder(ShadowsocksConfig config)
{
var tag = string.Empty;
var parts = $"{config.Method}:{config.Preplacedword}";
var base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(parts));
var websafeBase64 = base64.Replace('+', '-').Replace('/', '_').TrimEnd('=');
var plugin = string.Empty; // Reserve for future
if (!string.IsNullOrWhiteSpace(plugin))
{
plugin = "?plugin=" + WebUtility.UrlEncode(plugin);
}
var url = $"{websafeBase64}@{config.ServerHost}:{config.ServerPort}/{plugin}";
if (!string.IsNullOrEmpty(config.Name))
{
tag = $"#{WebUtility.UrlEncode(config.Name)}";
}
return $"ss://{url}{tag}";
}
19
View Source File : ApolloConfigurationProvider.cs
License : MIT License
Project Creator : zengqinglei
License : MIT License
Project Creator : zengqinglei
private bool UpdateNotifications()
{
try
{
var notificationsInput = JsonConvert.SerializeObject(
_namespaceNotifications,
new JsonSerializerSettings()
{
NullValueHandling = NullValueHandling.Ignore,
ContractResolver = new CamelCasePropertyNamesContractResolver()
});
var url = $"notifications/v2" +
$"?appId={_apolloOptions.AppId}" +
$"&cluster={_apolloOptions.Cluster}" +
$"¬ifications={WebUtility.UrlEncode(notificationsInput)}";
var response = _httpClient.GetAsync(url).GetAwaiter().GetResult();
response.EnsureSuccessStatusCode();
var notificationsResultString = response.Content.ReadreplacedtringAsync().GetAwaiter().GetResult();
var notificationsOutput = JsonConvert.DeserializeObject<List<NamespaceNotification>>(notificationsResultString);
foreach (var notificationOutput in notificationsOutput)
{
var namespaceNotification = _namespaceNotifications
.SingleOrDefault(m => m.NamespaceName == notificationOutput.NamespaceName);
if (namespaceNotification == null)
{
_namespaceNotifications.Add(notificationOutput);
}
else
{
namespaceNotification.NotificationId = notificationOutput.NotificationId;
}
GetRealtimeConfig(notificationOutput.NamespaceName);
}
WriteAppSettingsCache();
return true;
}
catch (Exception ex)
{
Console.WriteLine($"获取Apollo配置信息发生异常:{ex.ToString()}");
return false;
}
}
19
View Source File : SubtitleProviderBase.cs
License : MIT License
Project Creator : zerratar
License : MIT License
Project Creator : zerratar
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected static string GetUrlFriendlyName(string name)
{
return WebUtility.UrlEncode(Path.GetFileNameWithoutExtension(name));
}
19
View Source File : DefaultAccessTokenProvider.cs
License : Apache License 2.0
Project Creator : zhangzihan
License : Apache License 2.0
Project Creator : zhangzihan
public void SetHttpClientRequestAccessToken(HttpClient httpClient, string clientId, string tenantId, string name = null, string email = null, string phone = null)
{
httpClient.DefaultRequestHeaders.Remove("Authorization");
string accessToken = WebUtility.UrlEncode(JsonConvert.SerializeObject(new UserInfo
{
Id = string.IsNullOrWhiteSpace(clientId) ? WORKFLOW_CLIENT_ID : clientId,
FullName = name,
Email = email,
Phone = phone,
TenantId = tenantId
}));
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "Bearer " + accessToken);
}
19
View Source File : DefaultAccessTokenProvider.cs
License : Apache License 2.0
Project Creator : zhangzihan
License : Apache License 2.0
Project Creator : zhangzihan
public Task SetRequestAccessTokenAsync(HttpClient httpClient, HttpContext httpContext = null)
{
if (httpClient.DefaultRequestHeaders.Authorization != null)
{
return Task.CompletedTask;
}
string accessToken = null;
if (Authentication.AuthenticatedUser != null)
{
accessToken = WebUtility.UrlEncode(JsonConvert.SerializeObject(Authentication.AuthenticatedUser));
}
else if (httpContext != null)
{
accessToken = httpContext.Request.Headers["Authorization"].ToString()?.Split(' ')[1];
}
if (string.IsNullOrWhiteSpace(accessToken))
{
accessToken = WebUtility.UrlEncode(JsonConvert.SerializeObject(new
{
Id = WORKFLOW_CLIENT_ID
}));
}
httpClient.DefaultRequestHeaders.Remove("Authorization");
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "Bearer " + accessToken);
return Task.CompletedTask;
}
19
View Source File : IntegrationTestContext.cs
License : Apache License 2.0
Project Creator : zhangzihan
License : Apache License 2.0
Project Creator : zhangzihan
public IHttpClientProxy CreateHttpClientProxy(IUserInfo user = null)
{
HttpClient httpClient = Resolve<IHttpClientFactory>().CreateClient(); //TestServer.CreateClient();
httpClient.Timeout = TimeSpan.FromHours(1);
httpClient.BaseAddress = new Uri(Configuration.GetValue<string>("BaseUrl"));
string accessToken = WebUtility.UrlEncode(JsonConvert.SerializeObject(user ?? new UserInfo
{
Id = "8a010000-5d88-0015-e013-08d6bd87c815",
FullName = "新用户1",
TenantId = TenantId
}));
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
var session = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new
{
UserId = "8a010000-5d88-0015-e013-08d6bd87c815",
FullName = "新用户1",
TopOrgId = TenantId,
TenantId = TenantId
}));
_httpClient.DefaultRequestHeaders.Add("Evos-Authentication", WebEncoders.Base64UrlEncode(session));
DefaultHttpContext httpContext = new DefaultHttpContext();
return new DefaultHttpClientProxy(httpClient,
this.Resolve<IAccessTokenProvider>(),
new HttpContextAccessor()
{
HttpContext = httpContext
},
Resolve<ILoggerFactory>());
}
19
View Source File : IntegrationTestContext.cs
License : Apache License 2.0
Project Creator : zhangzihan
License : Apache License 2.0
Project Creator : zhangzihan
public WorkflowHttpClientProxyProvider CreateWorkflowHttpProxy()
{
_httpClient = Resolve<IHttpClientFactory>().CreateClient();//TestServer.CreateClient();
_httpClient.BaseAddress = new Uri(Configuration.GetValue<string>("BaseUrl"));
string accessToken = WebUtility.UrlEncode(JsonConvert.SerializeObject(new
{
Id = "8a010000-5d88-0015-e013-08d6bd87c815",
FullName = "新用户1",
TenantId
}));
if (_httpClient.DefaultRequestHeaders.Any(x => x.Key == "Authorization") == false)
{
_httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);
}
var session = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new
{
UserId = "8a010000-5d88-0015-e013-08d6bd87c815",
FullName = "新用户1",
TopOrgId = TenantId,
TenantId
}));
_httpClient.DefaultRequestHeaders.Add("Evos-Authentication", WebEncoders.Base64UrlEncode(session));
IHttpClientProxy clientProxy = Resolve<IHttpClientProxy>();
clientProxy.HttpClient = _httpClient;
return new WorkflowHttpClientProxyProvider(clientProxy);
}
19
View Source File : BaseControllerTest.cs
License : MIT License
Project Creator : zhontai
License : MIT License
Project Creator : zhontai
public string ToParams(object source)
{
var stringBuilder = new StringBuilder(string.Empty);
if (source == null)
{
return "";
}
var entries = from PropertyDescriptor property in TypeDescriptor.GetProperties(source)
let value = property.GetValue(source)
where value != null
select (property.Name, value);
foreach (var (name, value) in entries)
{
stringBuilder.Append(WebUtility.UrlEncode(name) + "=" + WebUtility.UrlEncode(value + "") + "&");
}
return stringBuilder.ToString().Trim('&');
}
19
View Source File : StringFlow.cs
License : MIT License
Project Creator : zmjack
License : MIT License
Project Creator : zmjack
public static string UrlEncode(string str) => WebUtility.UrlEncode(str);
See More Examples