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


C# HttpMethod.ToText方法代码示例

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


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

示例1: CreateOperationRequestMessage

        /// <summary>
        /// Creates an <see cref="ODataBatchOperationRequestMessage"/> for writing an operation of a batch request.
        /// </summary>
        /// <param name="method">The Http method to be used for this request operation.</param>
        /// <param name="uri">The Uri to be used for this request operation.</param>
        /// <param name="contentId">The (optional) content ID to be included in this request operation.</param>
        /// <returns>The message that can be used to write the request operation.</returns>
        public ODataBatchOperationRequestMessage CreateOperationRequestMessage(HttpMethod method, Uri uri, string contentId)
        {
            this.ValidateWriterReady();

            if (this.writingResponse)
            {
                this.ThrowODataException(Strings.ODataBatchWriter_CannotCreateRequestOperationWhenWritingResponse);
            }

            if (this.changeSetBoundary == null)
            {
                // only allow GET requests for query operations
                if (method != HttpMethod.Get)
                {
                    this.ThrowODataException(Strings.ODataBatchWriter_InvalidHttpMethodForQueryOperation(method.ToText()));
                }

                // do not allow content-id for query operations
                if (contentId != null)
                {
                    this.ThrowODataException(Strings.ODataBatchWriter_ContentIdNotSupportedForQueryOperations(contentId));
                }

                this.InterceptException(this.IncreaseBatchSize);
            }
            else
            {
                // allow all methods except for GET
                if (method == HttpMethod.Get)
                {
                    this.ThrowODataException(Strings.ODataBatchWriter_InvalidHttpMethodForChangeSetRequest(method.ToText()));
                }

                this.InterceptException(this.IncreaseChangeSetSize);
            }

            ExceptionUtils.CheckArgumentNotNull(uri, "uri");

            this.InterceptException(() => uri = ODataBatchWriterUtils.BuildAbsoluteUri(uri, this.settings.BaseUri));

            // write pending message data (headers, response line) for a previously unclosed message/request
            this.WritePendingMessageData(true);

            // create the new request operation
            this.CurrentOperationRequestMessage = new ODataBatchOperationRequestMessage(this.outputStream, method, uri, this);
            this.SetState(BatchWriterState.OperationCreated);

            // write the operation's start boundary string
            this.WriteStartBoundaryForOperation();

            // write the headers, request line and (optional) Content-ID
            ODataBatchWriterUtils.WriteRequestPreamble(this.batchWriter, method, uri, contentId);

            return this.CurrentOperationRequestMessage;
        }
开发者ID:rambo-returns,项目名称:MonoRail,代码行数:62,代码来源:ODataBatchWriter.cs

示例2: WriteRequestPreamble

        /// <summary>
        /// Writes the headers, (optional) Content-ID and the request line
        /// </summary>
        /// <param name="writer">Writer to write to.</param>
        /// <param name="method">The Http method to be used for this request operation.</param>
        /// <param name="uri">The Uri to be used for this request operation.</param>
        /// <param name="contentId">The (optional) content ID to be included in this request operation.</param>
        internal static void WriteRequestPreamble(StreamWriter writer, HttpMethod method, Uri uri, string contentId)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(writer != null, "writer != null");
            Debug.Assert(uri != null, "uri != null");
            Debug.Assert(uri.IsAbsoluteUri, "uri.IsAbsoluteUri");

            // write the headers
            writer.WriteLine("{0}: {1}", ODataHttpHeaders.ContentType, MimeConstants.MimeApplicationHttp);
            writer.WriteLine("{0}: {1}", HttpConstants.ContentTransferEncoding, HttpConstants.BatchRequestContentTransferEncoding);

            // write the optional content ID
            if (contentId != null)
            {
                writer.WriteLine("{0}: {1}", HttpConstants.ContentId, contentId);
            }

            // write separator line between headers and the request line
            writer.WriteLine();

            writer.WriteLine("{0} {1} {2}", method.ToText(), uri.AbsoluteUri, HttpConstants.HttpVersionInBatching);
        }
开发者ID:rambo-returns,项目名称:MonoRail,代码行数:29,代码来源:ODataBatchWriterUtils.cs


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