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


C# Response.GetOptions方法代码示例

本文整理汇总了C#中System.Net.Response.GetOptions方法的典型用法代码示例。如果您正苦于以下问题:C# Response.GetOptions方法的具体用法?C# Response.GetOptions怎么用?C# Response.GetOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Response的用法示例。


在下文中一共展示了Response.GetOptions方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetHttpResponse

        /// <summary>
        /// Sets the parameters of the incoming http response from a CoAP response.
	    /// The status code is mapped through the properties file and is set through
	    /// the StatusLine. The options are translated to the corresponding headers
	    /// and the max-age (in the header cache-control) is set to the default value
	    /// (60 seconds) if not already present. If the request method was not HEAD
	    /// and the coap response has a payload, the entity and the content-type are
        /// set in the http response.
        /// </summary>
        public static void GetHttpResponse(IHttpRequest httpRequest, Response coapResponse, IHttpResponse httpResponse)
        {
            if (httpRequest == null)
                throw ThrowHelper.ArgumentNull("httpRequest");
            if (coapResponse == null)
                throw ThrowHelper.ArgumentNull("coapResponse");
            if (httpResponse == null)
                throw ThrowHelper.ArgumentNull("httpResponse");

            HttpStatusCode httpCode;

            if (!coap2httpCode.TryGetValue(coapResponse.StatusCode, out httpCode))
                throw ThrowHelper.TranslationException("Cannot convert the coap code in http status code: " + coapResponse.StatusCode);

            httpResponse.StatusCode = (Int32)httpCode;

            NameValueCollection nvc = GetHttpHeaders(coapResponse.GetOptions());
            // set max-age if not already set
            if (nvc["cache-control"] == null)
                nvc.Set("cache-control", "max-age=" + CoapConstants.DefaultMaxAge);

            foreach (String key in nvc.Keys)
            {
                httpResponse.AppendHeader(key, nvc[key]);
            }

            Byte[] payload = coapResponse.Payload;
            if (payload != null)
            {
                httpResponse.OutputStream.Write(payload, 0, payload.Length);
                String contentType;
                if (coap2httpContentType.TryGetValue(coapResponse.ContentType, out contentType))
                    httpResponse.AppendHeader("content-type", contentType);
            }
        }
开发者ID:vjine,项目名称:CoAP.NET,代码行数:44,代码来源:HttpTranslator.cs


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