本文整理汇总了C#中StringBuilder.AppendUrlPath方法的典型用法代码示例。如果您正苦于以下问题:C# StringBuilder.AppendUrlPath方法的具体用法?C# StringBuilder.AppendUrlPath怎么用?C# StringBuilder.AppendUrlPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringBuilder
的用法示例。
在下文中一共展示了StringBuilder.AppendUrlPath方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestAppendUrlPathBasePathDoesNotEndInForwardSlashAppendedPathDoesNotBeginWithForwardSlash
public void TestAppendUrlPathBasePathDoesNotEndInForwardSlashAppendedPathDoesNotBeginWithForwardSlash()
{
var sb = new StringBuilder("/some");
Assert.AreEqual(sb, sb.AppendUrlPath("path"));
Assert.AreEqual("/some/path", sb.ToString());
}
示例2: TestAppendUrlPathBasePathIsEmpty
public void TestAppendUrlPathBasePathIsEmpty()
{
var sb = new StringBuilder();
Assert.AreEqual(sb, sb.AppendUrlPath("some/path"));
Assert.AreEqual("some/path", sb.ToString());
}
示例3: TestAppendUrlPathNull
public void TestAppendUrlPathNull()
{
var sb = new StringBuilder("/some/path");
Assert.AreEqual(sb, sb.AppendUrlPath(null));
Assert.AreEqual("/some/path", sb.ToString());
}
示例4: TestAppendUrlPathStringEmpty
public void TestAppendUrlPathStringEmpty()
{
var sb = new StringBuilder("/some/path");
Assert.AreEqual(sb, sb.AppendUrlPath(string.Empty));
Assert.AreEqual("/some/path/", sb.ToString());
}
示例5: GetResourceUri
internal Uri GetResourceUri(string path, ApiMethod method)
{
try
{
if ((path.StartsWith("https://", StringComparison.OrdinalIgnoreCase) &&
!path.StartsWith(this.ApiEndpoint, StringComparison.OrdinalIgnoreCase)) ||
path.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
{
return new Uri(path, UriKind.Absolute);
}
StringBuilder sb;
if (path.StartsWith(this.ApiEndpoint, StringComparison.OrdinalIgnoreCase))
{
sb = new StringBuilder(path);
}
else
{
sb = new StringBuilder(this.ApiEndpoint);
sb = sb.AppendUrlPath(path);
}
var resourceUrl = new Uri(sb.ToString(), UriKind.Absolute);
sb.Append(string.IsNullOrEmpty(resourceUrl.Query) ? "?" : "&");
if (method != ApiMethod.Download)
{
sb.AppendQueryParam(QueryParameters.SuppressResponseCodes, "true");
sb.Append("&").AppendQueryParam(QueryParameters.SuppressRedirects, "true");
}
return new Uri(sb.ToString(), UriKind.Absolute);
}
catch (FormatException)
{
throw new ArgumentException(
String.Format(CultureInfo.CurrentUICulture, ResourceHelper.GetString("UrlInvalid"), path),
"path");
}
}
示例6: ConstructUploadUri
private Uri ConstructUploadUri(string uploadLocation)
{
Uri resourceUrl;
try
{
// Do not forget to append the query string that was originally sent.
// this.Url contains the original query string plus suppress_response_codes and suppress_redirects.
// We will just reuse that.
string originalQueryString = this.Url.Query;
if (!string.IsNullOrWhiteSpace(originalQueryString))
{
// Uri.Query return contains "?" (e.g., ?key=value)
int indexOfQuestion = originalQueryString.IndexOf('?');
if (indexOfQuestion != -1)
{
originalQueryString = originalQueryString.Substring(indexOfQuestion + 1);
}
uploadLocation = uploadLocation.Contains("?")
? uploadLocation + "&" + originalQueryString
: uploadLocation + "?" + originalQueryString;
}
resourceUrl = new Uri(uploadLocation, UriKind.Absolute);
}
catch (FormatException exp)
{
throw new LiveConnectException(
ApiOperation.ApiClientErrorCode,
ResourceHelper.GetString("NoUploadLinkFound"),
exp);
}
string query = resourceUrl.Query;
string url = resourceUrl.GetComponents(
UriComponents.SchemeAndServer | UriComponents.Path | UriComponents.KeepDelimiter,
UriFormat.SafeUnescaped);
var sb = new StringBuilder(url);
if (!this.IsFilePath)
{
sb.AppendUrlPath(Uri.EscapeDataString(this.FileName));
}
bool hasQuery = !string.IsNullOrEmpty(query);
if (hasQuery)
{
sb.Append(query);
}
// Only add the overwrite parameter for folder uploads,
// since overwrite does not make sense on file path uploads (because they are always overwriting).
if (!this.IsFilePath)
{
sb.Append(hasQuery ? '&' : '?');
sb.AppendQueryParam(QueryParameters.Overwrite, QueryParameters.GetOverwriteValue(this.OverwriteOption));
}
try
{
return new Uri(sb.ToString(), UriKind.Absolute);
}
catch (FormatException exp)
{
throw new LiveConnectException(
ApiOperation.ApiClientErrorCode,
String.Format(CultureInfo.CurrentUICulture, ResourceHelper.GetString("FileNameInvalid"), "fileName"),
exp);
}
}