当前位置: 首页>>代码示例>>C#>>正文


C# HttpStatusCode.ToString方法代码示例

本文整理汇总了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());
        }
开发者ID:dstarosta,项目名称:GitProjects,代码行数:17,代码来源:HttpResponseException.cs

示例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 };
        }
开发者ID:jcteague,项目名称:hypermedia-tools,代码行数:12,代码来源:JsonCollection.cs

示例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));
     }
 }
开发者ID:kevinwrightleft,项目名称:mozu-dotnet,代码行数:28,代码来源:TestFailException.cs

示例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();
     }
 }
开发者ID:7763sea,项目名称:kuaipansdk,代码行数:26,代码来源:StatusCodeMsg.cs

示例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);
        }
开发者ID:cwillison94,项目名称:sar-tool,代码行数:33,代码来源:ErrorController.cs

示例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;
 }
开发者ID:PAOCjustin,项目名称:beanstream-dotnet,代码行数:8,代码来源:BaseApiException.cs

示例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();
 }
开发者ID:j0hn---,项目名称:peercaststation,代码行数:9,代码来源:HTTPUtils.cs

示例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();
 }
开发者ID:kumaryu,项目名称:peercaststation,代码行数:9,代码来源:HTTPUtils.cs

示例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;
 }
开发者ID:bettiolo,项目名称:ServiceStack,代码行数:10,代码来源:HttpError.cs

示例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;
 }
开发者ID:odelljl,项目名称:docs.particular.net,代码行数:10,代码来源:Program.cs

示例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.
        }
开发者ID:duszekmestre,项目名称:MoN.Messenger,代码行数:10,代码来源:HttpProcessor.cs

示例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
            };
        }
开发者ID:modulexcite,项目名称:W10Rpi2,代码行数:16,代码来源:ClientException.cs

示例13: GetMessage

        private static string GetMessage(HttpStatusCode statusCode, object content)
        {
            var result = statusCode.ToString();

            if (content != null)
            {
                result = result + " :" + content;
            }

            return result;
        }
开发者ID:BO45,项目名称:NzbDrone,代码行数:11,代码来源:ApiException.cs

示例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();
     }
 }
开发者ID:bigmlcom,项目名称:bigml-csharp,代码行数:11,代码来源:Debug.cs

示例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);
 }
开发者ID:rocketeerbkw,项目名称:DNA,代码行数:11,代码来源:LogUtility.cs


注:本文中的HttpStatusCode.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。