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


C# HttpRequest.ToWebRequest方法代码示例

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


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

示例1: op_ToWebRequest_HttpRequest

        public void op_ToWebRequest_HttpRequest()
        {
            var request = new HttpRequest
                              {
                                  Line = new HttpRequestLine("GET", "http://example.com/"),
                                  Headers = new HttpHeaderDictionary()
                              };

            Assert.NotNull(request.ToWebRequest().CookieContainer);
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:10,代码来源:HttpRequest.ExtensionMethods.Facts.cs

示例2: GetResponse

        public static HttpWebResponse GetResponse(HttpRequest request,
                                                  CookieContainer cookies)
        {
            try
            {
#if NET20
                return (HttpWebResponse)HttpRequestExtensionMethods.ToWebRequest(request, cookies).GetResponse();
#else
                return (HttpWebResponse)request.ToWebRequest(cookies).GetResponse();
#endif
            }
            catch (WebException exception)
            {
                return (HttpWebResponse)exception.Response;
            }
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:16,代码来源:HttpExpectation.cs

示例3: op_ToWebRequest_HttpRequest_CookieContainer

        public void op_ToWebRequest_HttpRequest_CookieContainer()
        {
            var cookies = new CookieContainer();
            var request = new HttpRequest
                              {
                                  Line = new HttpRequestLine("GET", "http://example.com/"),
                                  Headers = new HttpHeaderDictionary()
                              };

            request.Headers[HttpGeneralHeaders.CacheControl] = "no-cache";
            request.Headers[HttpGeneralHeaders.Date] = "Tue, 15 Nov 1994 08:12:31 GMT";
            request.Headers[HttpGeneralHeaders.Pragma] = "name=value";
            request.Headers[HttpGeneralHeaders.TransferEncoding] = "chunked";
            request.Headers[HttpGeneralHeaders.Upgrade] = "HTTP/2.0";
            request.Headers[HttpGeneralHeaders.Via] = "1.0 fred, 1.1 nowhere.com (Apache/1.1)";
            request.Headers[HttpGeneralHeaders.Warning] = "199 Miscellaneous warning";

            request.Headers[HttpEntityHeaders.Expires] = "Thu, 01 Dec 1994 16:00:00 GMT";
            request.Headers[HttpEntityHeaders.LastModified] = "Tue, 15 Nov 1994 12:45:26 GMT";

            request.Headers[HttpRequestHeaders.Accept] = "*/*";
            request.Headers[HttpRequestHeaders.AcceptCharset] = "*";
            request.Headers[HttpRequestHeaders.AcceptEncoding] = "*";
            request.Headers[HttpRequestHeaders.AcceptLanguage] = "*";
            request.Headers[HttpRequestHeaders.Authorization] = "credentials";
            request.Headers[HttpRequestHeaders.From] = "[email protected]";
            request.Headers[HttpRequestHeaders.Host] = "example.com";
            request.Headers[HttpRequestHeaders.IfMatch] = "*";
            request.Headers[HttpRequestHeaders.IfModifiedSince] = "Sat, 29 Oct 1994 19:43:31 GMT";
            request.Headers[HttpRequestHeaders.IfNoneMatch] = "*";
            request.Headers[HttpRequestHeaders.IfRange] = "*";
            request.Headers[HttpRequestHeaders.IfUnmodifiedSince] = "Sat, 29 Oct 1994 19:43:31 GMT";
            request.Headers[HttpRequestHeaders.ProxyAuthorization] = "credentials";
            request.Headers[HttpRequestHeaders.Range] = "bytes=0-7";
            request.Headers[HttpRequestHeaders.Referer] = "http://example.net/";
            request.Headers[HttpRequestHeaders.Range] = "bytes=0-7";
            request.Headers[HttpRequestHeaders.TE] = "deflate";
            request.Headers[HttpRequestHeaders.UserAgent] = "Example Facts";
            request.Headers[HttpRequestHeaders.Vary] = "*";

            var actual = request.ToWebRequest(cookies);

            Assert.False(actual.AllowAutoRedirect);
            Assert.Equal((string)request.Line.Method, actual.Method);
            Assert.Equal((string)request.Line.RequestUri, actual.Address.AbsoluteUri);

            Assert.Same(cookies, actual.CookieContainer);

            Assert.Equal(request.Headers[HttpGeneralHeaders.CacheControl], actual.Headers[HttpRequestHeader.CacheControl]);
#if NET20 || NET35
#else
            Assert.Equal(request.Headers[HttpGeneralHeaders.Date], actual.Headers[HttpRequestHeader.Date]);
#endif
            Assert.Equal(request.Headers[HttpGeneralHeaders.Pragma], actual.Headers[HttpRequestHeader.Pragma]);
            Assert.Equal(request.Headers[HttpGeneralHeaders.Upgrade], actual.Headers[HttpRequestHeader.Upgrade]);
            Assert.Equal(request.Headers[HttpGeneralHeaders.Via], actual.Headers[HttpRequestHeader.Via]);
            Assert.Equal(request.Headers[HttpGeneralHeaders.Warning], actual.Headers[HttpRequestHeader.Warning]);

            Assert.Equal(request.Headers[HttpEntityHeaders.Expires], actual.Headers[HttpRequestHeader.Expires]);
            Assert.Equal(request.Headers[HttpEntityHeaders.LastModified], actual.Headers[HttpRequestHeader.LastModified]);

            Assert.Equal(request.Headers[HttpRequestHeaders.Accept], actual.Accept);
            Assert.Equal(request.Headers[HttpRequestHeaders.AcceptCharset], actual.Headers[HttpRequestHeader.AcceptCharset]);
            Assert.Equal(request.Headers[HttpRequestHeaders.AcceptEncoding], actual.Headers[HttpRequestHeader.AcceptEncoding]);
            Assert.Equal(request.Headers[HttpRequestHeaders.AcceptLanguage], actual.Headers[HttpRequestHeader.AcceptLanguage]);
            Assert.Equal(request.Headers[HttpRequestHeaders.Authorization], actual.Headers[HttpRequestHeader.Authorization]);
            Assert.Equal(request.Headers[HttpRequestHeaders.From], actual.Headers[HttpRequestHeader.From]);
            Assert.Null(actual.Headers[HttpRequestHeaders.Host]);
            Assert.Equal(request.Headers[HttpRequestHeaders.IfMatch], actual.Headers[HttpRequestHeader.IfMatch]);
            Assert.Equal(request.Headers[HttpRequestHeaders.IfModifiedSince], actual.Headers[HttpRequestHeader.IfModifiedSince]);
            Assert.Equal(request.Headers[HttpRequestHeaders.IfNoneMatch], actual.Headers[HttpRequestHeader.IfNoneMatch]);
            Assert.Equal(request.Headers[HttpRequestHeaders.IfRange], actual.Headers[HttpRequestHeader.IfRange]);
            Assert.Equal(request.Headers[HttpRequestHeaders.IfUnmodifiedSince], actual.Headers[HttpRequestHeader.IfUnmodifiedSince]);
            Assert.Equal(request.Headers[HttpRequestHeaders.ProxyAuthorization], actual.Headers[HttpRequestHeader.ProxyAuthorization]);
            Assert.Null(actual.Headers[HttpRequestHeader.Range]);
            Assert.Equal(request.Headers[HttpRequestHeaders.Referer], actual.Headers[HttpRequestHeader.Referer]);
            Assert.Equal(request.Headers[HttpRequestHeaders.TE], actual.Headers[HttpRequestHeader.Te]);
            Assert.Equal(request.Headers[HttpRequestHeaders.UserAgent], actual.Headers[HttpRequestHeader.UserAgent]);
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:79,代码来源:HttpRequest.ExtensionMethods.Facts.cs

示例4: op_ToWebRequest_HttpRequest_CookieContainer_whenTrace

        public void op_ToWebRequest_HttpRequest_CookieContainer_whenTrace()
        {
            var cookies = new CookieContainer();
            var request = new HttpRequest
                              {
                                  Line = new HttpRequestLine("TRACE", "http://example.com/"),
                                  Headers = new HttpHeaderDictionary()
                              };

            request.Headers["Max-Forwards"] = "3";

            var actual = request.ToWebRequest(cookies);

            Assert.Equal((string)request.Line.Method, actual.Method);
            Assert.Equal((string)request.Line.RequestUri, actual.Address.AbsoluteUri);

            Assert.Same(cookies, actual.CookieContainer);

            Assert.Equal(request.Headers["Max-Forwards"], actual.Headers[HttpRequestHeader.MaxForwards]);
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:20,代码来源:HttpRequest.ExtensionMethods.Facts.cs

示例5: op_ToWebRequest_HttpRequest_CookieContainer_whenOnlyLine

        public void op_ToWebRequest_HttpRequest_CookieContainer_whenOnlyLine()
        {
            var cookies = new CookieContainer();
            var request = new HttpRequest
                              {
                                  Line = new HttpRequestLine("GET", "http://example.com/")
                              };

            var actual = request.ToWebRequest(cookies);

            Assert.Equal((string)request.Line.Method, actual.Method);
            Assert.Equal((string)request.Line.RequestUri, actual.Address.AbsoluteUri);

            Assert.Same(cookies, actual.CookieContainer);
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:15,代码来源:HttpRequest.ExtensionMethods.Facts.cs


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