本文整理汇总了C#中System.Uri.GetComponents方法的典型用法代码示例。如果您正苦于以下问题:C# Uri.GetComponents方法的具体用法?C# Uri.GetComponents怎么用?C# Uri.GetComponents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Uri
的用法示例。
在下文中一共展示了Uri.GetComponents方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFileStream
public override Stream GetFileStream(Uri path)
{
string modFile = path.GetComponents(UriComponents.Host, UriFormat.UriEscaped);
string filePath = path.GetComponents(UriComponents.Path, UriFormat.UriEscaped);
return GetFileStream(directory + modFile + "/", filePath);
}
示例2: GetFilepath
private string GetFilepath(string url)
{
var asUri = new Uri(url);
string cleanUrl;
if(asUri.Scheme != "file") {
#if UNITY_EDITOR
cleanUrl = asUri.GetComponents(UriComponents.Path, UriFormat.Unescaped);
// Read resources from the project folder
var uiResources = PlayerPrefs.GetString("CoherentUIResources");
if (uiResources == string.Empty)
{
Debug.LogError("Missing path for Coherent UI resources. Please select path to your resources via Edit -> Project Settings -> Coherent UI -> Select UI Folder");
// Try to fall back to the default location
uiResources = Path.Combine(Path.Combine(Application.dataPath, "WebPlayerTemplates"), "uiresources");
Debug.LogWarning("Falling back to the default location of the UI Resources in the Unity Editor: " + uiResources);
PlayerPrefs.SetString("CoherentUIResources", "WebPlayerTemplates/uiresources");
} else {
uiResources = Path.Combine(Application.dataPath, uiResources);
}
cleanUrl = cleanUrl.Insert(0, uiResources + '/');
#else
cleanUrl = asUri.GetComponents(UriComponents.Host | UriComponents.Path, UriFormat.Unescaped);
// Read resources from the <executable>_Data folder
cleanUrl = Application.dataPath + '/' + cleanUrl;
#endif
}
else {
cleanUrl = asUri.GetComponents(UriComponents.Path, UriFormat.Unescaped);
}
return cleanUrl;
}
示例3: GetFilepath
private string GetFilepath(string url)
{
var asUri = new Uri(url);
string cleanUrl;
if(asUri.Scheme != "file") {
#if UNITY_EDITOR
cleanUrl = asUri.GetComponents(UriComponents.Path, UriFormat.Unescaped);
// Read resources from the project folder
var uiResources = PlayerPrefs.GetString("CoherentUIResources");
if (uiResources == string.Empty)
{
Debug.LogError("Missing path for Coherent UI resources. Please select path to your resources via Edit -> Project Settings -> Coherent UI -> Select UI Folder");
}
cleanUrl = cleanUrl.Insert(0, uiResources + '/');
#else
cleanUrl = asUri.GetComponents(UriComponents.Host | UriComponents.Path, UriFormat.Unescaped);
// Read resources from the <executable>_Data folder
cleanUrl = Application.dataPath + '/' + cleanUrl;
#endif
}
else {
cleanUrl = asUri.GetComponents(UriComponents.Path, UriFormat.Unescaped);
}
return cleanUrl;
}
示例4: CreatePostRequest
/// <summary>
/// Create a HttpWebRequest using the HTTP POST method.
/// </summary>
/// <param name="requestUri">URI to request.</param>
/// <param name="writeBody">Whether it should write the contents of the body.</param>
/// <returns>HttpWebRequest for this URI.</returns>
private static HttpWebRequest CreatePostRequest(Uri requestUri, bool writeBody)
{
var uriWithoutQuery = new Uri(requestUri.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.Unescaped));
var postRequest = WebRequest.CreateHttp(uriWithoutQuery);
postRequest.Method = "POST";
var bodyWithQuery = requestUri.GetComponents(UriComponents.Query, UriFormat.UriEscaped);
var bodyBytes = Encoding.UTF8.GetBytes(bodyWithQuery);
#if !WINDOWS_PHONE_APP
postRequest.ContentLength = bodyBytes.Length;
#endif
if (writeBody)
{
#if WINDOWS_PHONE_APP
var stream = postRequest.GetRequestStreamAsync().Result;
#else
var stream = postRequest.GetRequestStream();
#endif
stream.Write(bodyBytes, 0, bodyBytes.Length);
#if WINDOWS_PHONE_APP
stream.Flush();
stream.Dispose();
#else
stream.Close();
#endif
}
return postRequest;
}
示例5: BindUri
public static Uri BindUri(this ISession session, Uri url, object parameters = null)
{
Uri baseUri = new Uri(url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped));
UriTemplate template = new UriTemplate(url.GetComponents(UriComponents.PathAndQuery, UriFormat.Unescaped));
return BindTemplate(baseUri, template, parameters);
}
示例6: ExistsInPath
public override bool ExistsInPath(Uri path)
{
string modFile = path.GetComponents(UriComponents.Host, UriFormat.UriEscaped);
string filePath = path.GetComponents(UriComponents.Path, UriFormat.UriEscaped);
return ExistsInPath(directory + modFile + "/", filePath);
}
示例7: GenerateSignature
static string GenerateSignature(string consumerSecret, Uri uri, HttpMethod method, Token token, IEnumerable<KeyValuePair<string, string>> parameters)
{
if (ComputeHash == null)
{
throw new InvalidOperationException("ComputeHash is null, must initialize before call OAuthUtility.HashFunction = /* your computeHash code */ at once.");
}
var hmacKeyBase = consumerSecret.UrlEncode() + "&" + ((token == null) ? "" : token.Secret).UrlEncode();
// escaped => unescaped[]
var queryParams = Utility.ParseQueryString(uri.GetComponents(UriComponents.Query | UriComponents.KeepDelimiter, UriFormat.UriEscaped));
var stringParameter = parameters
.Where(x => x.Key.ToLower() != "realm")
.Concat(queryParams)
.Select(p => new { Key = p.Key.UrlEncode(), Value = p.Value.UrlEncode() })
.OrderBy(p => p.Key, StringComparer.Ordinal)
.ThenBy(p => p.Value, StringComparer.Ordinal)
.Select(p => p.Key + "=" + p.Value)
.ToString("&");
var signatureBase = method.ToString() +
"&" + uri.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.Unescaped).UrlEncode() +
"&" + stringParameter.UrlEncode();
var hash = ComputeHash(Encoding.UTF8.GetBytes(hmacKeyBase), Encoding.UTF8.GetBytes(signatureBase));
return Convert.ToBase64String(hash).UrlEncode();
}
示例8: CreateRequest
/// <summary>
/// Creates the HttpRequestMessage for a URI taking into consideration the length.
/// For URIs over 2000 bytes it will be a GET otherwise it will become a POST
/// with the query payload moved to the POST body.
/// </summary>
/// <param name="uri">URI to request.</param>
/// <returns>HttpRequestMessage for this URI.</returns>
internal static HttpRequestMessage CreateRequest(Uri uri)
{
if (!uri.ShouldUsePostForRequest())
return new HttpRequestMessage(HttpMethod.Get, uri);
var uriWithoutQuery = new Uri(uri.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.Unescaped));
return new HttpRequestMessage(HttpMethod.Post, uriWithoutQuery) { Content = new StringContent(uri.GetComponents(UriComponents.Query, UriFormat.UriEscaped)) };
}
示例9: Bind
/// <summary>
/// Resolve absolute string URI template and create request with implicit session.
/// </summary>
/// <param name="url"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public static Request Bind(this string url, object parameters = null)
{
Condition.Requires(url, "url").IsNotNull();
Uri uri = new Uri(url);
Uri baseUri = new Uri(uri.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped));
UriTemplate template = new UriTemplate(uri.GetComponents(UriComponents.PathAndQuery, UriFormat.Unescaped));
Uri boundUrl = BindTemplate(baseUri, template, parameters);
return new Request(boundUrl);
}
示例10: FactoryParameters
/// <summary>
/// Creates a new factory parameter by splitting the specified service URI into ServerUrl and BasePath
/// </summary>
public FactoryParameters(Uri serviceUri)
{
serviceUri.ThrowIfNull("serviceUri");
// Retrieve Scheme and Host
ServerUrl = serviceUri.GetComponents(UriComponents.SchemeAndServer, UriFormat.UriEscaped);
ServerUrl.ThrowIfNullOrEmpty("ServerUrl");
// Retrieve the remaining right part
BasePath = serviceUri.GetComponents(UriComponents.PathAndQuery, UriFormat.UriEscaped);
ServerUrl.ThrowIfNullOrEmpty("BasePath");
}
示例11: GetImages
public async Task<ImageInfo[]> GetImages(Match match)
{
var id = match.Groups[1].Value;
var uri = new Uri(
match.Groups[2].Success
? match.Value
: await this._memoryCache.GetOrSet("gyazo-" + id, () => this.Fetch(id)).ConfigureAwait(false)
);
var full = uri.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.UriEscaped);
var thumb = uri.GetComponents(UriComponents.SchemeAndServer, UriFormat.UriEscaped)
+ "/thumb/180" + uri.AbsolutePath;
return new[] { new ImageInfo(full, full, thumb) };
}
示例12: Main
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
FormMain f = new FormMain();
f.Text += " by chall3ng3r.com - v" + Application.ProductVersion;
foreach (string s in args)
{
try
{
// make http URI
Uri uri = new Uri(s);
string strURL = "http://";
strURL += uri.GetComponents(UriComponents.HostAndPort, UriFormat.UriEscaped);
strURL += "/" + uri.GetComponents(UriComponents.Path, UriFormat.UriEscaped);
// window size from querystring
NameValueCollection queryVars = ParseQueryString(uri.GetComponents(UriComponents.Query, UriFormat.Unescaped));
string size = queryVars.Get("size");
if(!string.IsNullOrEmpty(size))
{
// maximize
if (size.ToLower() == "fullscreen")
{
f.WindowState = FormWindowState.Maximized;
}
// resize window to specified width,height
else
{
int w = Convert.ToInt32(size.Split(',')[0]);
int h = Convert.ToInt32(size.Split(',')[1]);
f.Width = w;
f.Height = h;
}
}
f.initUnity(strURL);
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
}
Application.Run(f);
}
示例13: FromUri
/// <summary>
/// Takes the arguments in the form of a <see cref="Uri"/> and
/// converts them to a <see cref="VersionControlArguments"/>.
/// </summary>
/// <param name="uri">The URI specifying the arguments.</param>
/// <returns></returns>
public static VersionControlArguments FromUri(Uri uri)
{
if (uri == null) throw new ArgumentNullException("uri");
var args = new VersionControlArguments
{
Provider = uri.Scheme,
Server = uri.GetComponents(UriComponents.HostAndPort, UriFormat.UriEscaped)
};
if (!uri.UserInfo.IsNullOrEmpty())
{
var parts = uri.UserInfo.Split(new[] { ':' });
var userName = parts[0];
var password = parts[1];
args.Credentials = new NetworkCredential(userName, password);
}
// The project name is the first part of the path
args.Project = Uri.UnescapeDataString(uri.Segments[1]).Trim('/', '\\');
// Query string arguments
var queryStringArgs = ParseQueryStringArgs(uri);
if( queryStringArgs.ContainsKey("label")) args.Label = Uri.UnescapeDataString(queryStringArgs["label"]);
if (queryStringArgs.ContainsKey("destinationpath")) args.DestinationPath = Uri.UnescapeDataString(queryStringArgs["destinationpath"]);
return args;
}
示例14: ForceHostToUseWww
public void ForceHostToUseWww()
{
var target = CreateRuleSet(@"
RewriteCond %{HTTP_HOST} !^(www).*$ [NC]
RewriteRule ^(.*)$ http://www.%1$1 [R=301]");
var url = new Uri("http://somesite.com/pass");
var context = HttpHelpers.MockHttpContext(url);
context.Request.SetServerVariables(new Dictionary<string, string> {
{ "HTTP_HOST", url.GetComponents(UriComponents.Host, UriFormat.SafeUnescaped) }
});
string expected = "http://www.somesite.com/pass";
Uri resultUrl = target.RunRules(context, url);
string result = context.Response.RedirectLocation;
Assert.IsNull(resultUrl);
Assert.AreEqual(expected, result);
url = new Uri("http://www.somesite.com/fail");
context = HttpHelpers.MockHttpContext(url);
context.Request.SetServerVariables(new Dictionary<string, string> {
{ "HTTP_HOST", url.GetComponents(UriComponents.Host, UriFormat.SafeUnescaped) }
});
resultUrl = target.RunRules(context, url);
result = context.Response.RedirectLocation;
Assert.IsNull(resultUrl);
Assert.IsNull(result);
}
示例15: ExtractParameters
/// <summary>
/// Extract the query string parameters from a URI into a dictionary of keys and values.
/// </summary>
/// <param name="uri">URI to extract the parameters from.</param>
/// <returns>Dictionary of keys and values representing the parameters.</returns>
private static Dictionary<string, string> ExtractParameters(Uri uri)
{
return uri.GetComponents(UriComponents.Query, UriFormat.SafeUnescaped)
.Split('&')
.Select(kv => kv.Split('='))
.ToDictionary(k => k[0], v => Uri.UnescapeDataString(v[1]));
}