本文整理汇总了C#中HttpStatusCode.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# HttpStatusCode.ToString方法的具体用法?C# HttpStatusCode.ToString怎么用?C# HttpStatusCode.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpStatusCode
的用法示例。
在下文中一共展示了HttpStatusCode.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HttpResponseException
/// <summary>
/// Initializes a new instance of the <see cref="HttpResponseException"/> class with the HTTP status code and description.
/// </summary>
/// <param name="statusCode">The status code.</param>
/// <param name="statusDescription">The status description.</param>
/// <exception cref="ArgumentException">If the status code is not an error code.</exception>
public HttpResponseException(HttpStatusCode statusCode, string statusDescription) :
base(String.Format(CultureInfo.InvariantCulture, "HTTP Status Exception: ({0}) {1}", (int) statusCode, statusDescription ?? PascalCaseToSentenceConverter.Convert(statusCode.ToString())))
{
if ((int) statusCode < MinErrorStatusCode)
{
throw new ArgumentException(Resources.Global.NonErrorHttpStatusCode, "statusCode");
}
StatusCode = statusCode;
StatusDescription = statusDescription ?? PascalCaseToSentenceConverter.Convert(statusCode.ToString());
}
示例2: ForErrors
public static JsonCollection ForErrors( IEnumerable<string> errors, HttpStatusCode code, string title )
{
var collection = new Collection {
error = new CollectionMessage {
code = code.ToString(),
messages = errors,
title = title ?? code.ToString( )
}
};
return new JsonCollection { collection = collection };
}
示例3: GetCustomTestException
public static Exception GetCustomTestException(ApiException apiException, string currentClassName, string currentMethodName, HttpStatusCode expectedCode)
{
var correlationId = apiException.CorrelationId;
var printableError = string.Format("{0} || {1}.{2} {3} | Error: {4} | CorrelationId: {5}",
apiException.HttpStatusCode.ToString(),
currentClassName, currentMethodName,
apiException.ApplicationName ?? "", apiException.Message ?? "",
correlationId
);
Debug.WriteLine(printableError);
switch (apiException.HttpStatusCode)
{
case HttpStatusCode.NotFound:
return null; // or use new Exception("No Item Found with API transaction.") ;
case HttpStatusCode.NoContent:
return null; // or use new Exception("No Content was returned by the API") ;
case HttpStatusCode.Unauthorized:
return new Exception("Unauthorized Access To this API, Please check your behaviors and possibly re-install the application to this store to pick up changes.");
case HttpStatusCode.Forbidden:
return new Exception("Forbidden Access To this API, Please check your SiteId settings and possibly re-install the application to this store.");
default:
return new Exception(String.Format("Test Fails - [{0}:expected {1}] but the actual return code is {2}. {3}",
currentMethodName,
expectedCode.ToString(),
apiException.HttpStatusCode,
printableError));
}
}
示例4: GetMsg
public static string GetMsg(HttpStatusCode code)
{
switch (code)
{
case HttpStatusCode.OK:
return "正常返回";
case HttpStatusCode.Accepted:
return "接口执行错误,错误信息可以看msg";
case HttpStatusCode.BadRequest:
return "参数错误";
case HttpStatusCode.Unauthorized:
return "请求验证错误";
case HttpStatusCode.Forbidden:
return "无权限操作";
case HttpStatusCode.NotFound:
return "无此文件";
case HttpStatusCode.NotAcceptable:
return "同时操作太多文件";
case HttpStatusCode.RequestEntityTooLarge:
return "文件太大";
case HttpStatusCode.InternalServerError:
return "服务器内部错误";
default:
return code.ToString();
}
}
示例5: Display
public static HttpContent Display(HttpRequest request, Exception ex, HttpStatusCode status)
{
Exception inner = ExceptionHelper.GetInner(ex);
var baseContent = new Dictionary<string, HttpContent>() {};
baseContent.Add("Title", new HttpContent(status.ToString()));
baseContent.Add("ResponseCode", new HttpContent(((int)status).ToString()));
baseContent.Add("ExceptionType", new HttpContent(inner.GetType().ToString()));
baseContent.Add("RequestURL", new HttpContent(request.FullUrl));
baseContent.Add("ExceptionMessage", new HttpContent(inner.Message));
string stackTrace = "";
if (inner != ex)
{
stackTrace += "<span><strong>Outer:</strong><br>";
stackTrace += "<cite>" + ExceptionHelper.GetStackTrace(ex) + "</cite></span>";
stackTrace += Environment.NewLine;
stackTrace += "<span><strong>Inner:</strong><br>";
stackTrace += "<cite>" + ExceptionHelper.GetStackTrace(inner) + "</cite></span>";
}
else
{
stackTrace += "<cite>" + ExceptionHelper.GetStackTrace(ex) + "</cite>";
}
stackTrace = stackTrace.Replace("\t", "");
baseContent.Add("ExceptionStackTrace", new HttpContent(stackTrace.ToHTML()));
lastException = baseContent;
return HttpContent.Read(request.Server, "sar.Http.Views.Error.Display.html", baseContent);
}
示例6: BaseApiException
protected BaseApiException(HttpStatusCode statusCode, string response, int category, int code)
: base(statusCode.ToString()+", category: "+category+", code: "+code+": "+response)
{
_response = response;
_statusCode = statusCode;
_category = category;
_code = code;
}
示例7: CreateResponseHeader
public static string CreateResponseHeader(HttpStatusCode code, Dictionary<string, string> parameters)
{
var header = new System.Text.StringBuilder(String.Format("HTTP/1.0 {0} {1}\r\n", (int)code, code.ToString()));
foreach (var param in parameters) {
header.AppendFormat("{0}: {1}\r\n", param.Key, param.Value);
}
header.Append("\r\n");
return header.ToString();
}
示例8: CreateResponseHeader
public static string CreateResponseHeader(HttpStatusCode code)
{
var header = new System.Text.StringBuilder(String.Format("HTTP/1.0 {0} {1}\r\n", (int)code, code.ToString()));
if (code==HttpStatusCode.Unauthorized) {
header.AppendFormat("{0}: {1}\r\n", "WWW-Authenticate", "Basic realm=\"PeerCastStation\"");
}
header.Append("\r\n");
return header.ToString();
}
示例9: HttpError
public HttpError(HttpStatusCode statusCode = HttpStatusCode.InternalServerError, string errorMessage = null,
string errorCode = null, object responseDto = null, HttpError innerException = null)
: base(errorMessage ?? errorCode ?? statusCode.ToString(), innerException)
{
this.Response = responseDto;
this.ErrorCode = errorCode;
this.StatusCode = statusCode;
this.Headers = new Dictionary<string, string>();
this.StatusDescription = errorCode;
}
示例10: WriteResponse
static void WriteResponse(HttpListenerResponse response, HttpStatusCode statusCode)
{
response.StatusCode = (int)statusCode;
string text = statusCode.ToString();
using (StreamWriter streamWriter = new StreamWriter(response.OutputStream))
{
streamWriter.Write(text);
}
response.StatusDescription = text;
}
示例11: WriteFail
public async Task WriteFail(HttpStatusCode statusCode)
{
// this is an http 404 failure response
await Output.WriteLineAsync($"{this.Request.HttpProtocolVersion ?? "HTTP/1.0"} {(int)statusCode} {statusCode.ToString()}");
// these are the HTTP headers
await Output.WriteLineAsync("Connection: close");
// ..add your own headers here
await Output.WriteLineAsync(""); // this terminates the HTTP headers.
}
示例12: ClientException
/// <summary>
/// Initializes a new instance of the <see cref="ClientException"/> class.
/// </summary>
/// <param name="message">The corresponding error message.</param>
/// <param name="httpStatus">The Http Status code.</param>
public ClientException(string message, HttpStatusCode httpStatus)
: base(message)
{
HttpStatus = httpStatus;
Error = new ClientError()
{
Code = HttpStatus.ToString(),
Message = message
};
}
示例13: GetMessage
private static string GetMessage(HttpStatusCode statusCode, object content)
{
var result = statusCode.ToString();
if (content != null)
{
result = result + " :" + content;
}
return result;
}
示例14: printResponseDebug
private void printResponseDebug(HttpStatusCode code, HttpContent response)
{
if (this._debug)
{
Console.WriteLine(" >>>>>> " + code.ToString() + " >>>>>> ");
Console.WriteLine(response);
Console.WriteLine();
Console.WriteLine();
Console.WriteLine();
}
}
示例15: LogResponse
public static void LogResponse(this IDnaLogger logger,HttpStatusCode httpStatusCode, HttpResponseMessage httpResponse)
{
var props = new Dictionary<string, object>()
{
{ "Result", httpStatusCode.ToString()},
{ "Uri", httpResponse.Uri.ToString()},
{ "Content", httpResponse.Content.ReadAsString()}
};
string category = Assembly.GetCallingAssembly().GetName().Name + ".Responses";
logger.LogGeneral(TraceEventType.Information, category, "", DateTime.MaxValue, props);
}