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


C# HttpWebRequest.GetType方法代码示例

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


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

示例1: Config

        public override void Config(HttpWebRequest req,
            bool? allowAutoRedirect = null,
            TimeSpan? timeout = null,
            TimeSpan? readWriteTimeout = null,
            string userAgent = null,
            bool? preAuthenticate = null)
        {
            //throws NotImplementedException in both BrowserHttp + ClientHttp
            //if (allowAutoRedirect.HasValue) req.AllowAutoRedirect = allowAutoRedirect.Value;
            //if (userAgent != null) req.UserAgent = userAgent; 

            //Methods others than GET and POST are only supported by Client request creator, see
            //http://msdn.microsoft.com/en-us/library/cc838250(v=vs.95).aspx
            if (req.GetType().Name != "BrowserHttpWebRequest") return;
            if (req.Method != "GET" && req.Method != "POST")
            {
                req.Headers[HttpHeaders.XHttpMethodOverride] = req.Method;
                req.Method = "POST";
            }
        }
开发者ID:Nezz,项目名称:ServiceStack.Text,代码行数:20,代码来源:PclExport.Sl5.cs

示例2: ApiRequest

        /// <summary>
        /// Create a new API request.
        /// </summary>
        /// <param name="authInfo">The authentication info to send to the server.</param>
        /// <param name="requestPath">The API request path. You can use the constants given in <see cref="ApiRequest"/>.</param>
        public ApiRequest(AuthenticationInfo authInfo, string requestPath)
        {
            if (!authInfo.Authenticated)
                throw new InvalidOperationException(Properties.Resources.ExceptionUnauthenticatedState);
            WebRequest = (HttpWebRequest)System.Net.WebRequest.Create(
                CreateApiUrl(authInfo, requestPath));
            WebRequest.Accept = "application/xml";

            PropertyInfo headerInfo = WebRequest.GetType().GetProperty("UserAgent");

            if (headerInfo != null)
            {
                headerInfo.SetValue(WebRequest, "MyAquinasMobileAPI", null);
            }
            else
            {
                WebRequest.Headers[HttpRequestHeader.UserAgent] = "MyAquinasMobileAPI";
            }

            WebRequest.Headers["AuthToken"] = authInfo.Token.ToString();
        }
开发者ID:Quackmatic,项目名称:AquinasAPI,代码行数:26,代码来源:ApiRequest.cs

示例3: setAgent

        private static void setAgent(HttpWebRequest request, string agent)
        {
            bool userAgentSet = false;
            if (SetUserAgentUsingReflection)
            {
                try
                {
#if PORTABLE45
					System.Reflection.PropertyInfo prop = request.GetType().GetRuntimeProperty("UserAgent");
#else
                    System.Reflection.PropertyInfo prop = request.GetType().GetProperty("UserAgent");
#endif

                    if (prop != null)
                        prop.SetValue(request, agent, null);
                    userAgentSet = true;
                }
                catch (Exception)
                {
                    // This approach doesn't work on this platform, so don't try it again.
                    SetUserAgentUsingReflection = false;
                }
            }
            if (!userAgentSet && SetUserAgentUsingDirectHeaderManipulation)
            {
                // platform does not support UserAgent property...too bad
                try
                {
                    request.Headers[HttpRequestHeader.UserAgent] = agent;
                }
                catch (ArgumentException)
                {
                    SetUserAgentUsingDirectHeaderManipulation = false;
                }
            }
        }
开发者ID:molsches,项目名称:fhir-net-api,代码行数:36,代码来源:EntryToHttpExtensions.cs

示例4: BeginAuthenticate

        /// <summary>
        /// Begins an asynchronous API authentication request.
        /// </summary>
        /// <param name="callback">The asynchronous callback for the web request</param>
        /// <returns>An XDocument containing the result of the request.</returns>
        public IAsyncResult BeginAuthenticate(AsyncCallback callback)
        {
            Request = (HttpWebRequest)System.Net.WebRequest.Create(
                Properties.Resources.AuthenticationUrl);
            Request.Method = "POST";
            Request.ContentType = "application/xml";
            PropertyInfo headerInfo = Request.GetType().GetProperty("UserAgent");

            if (headerInfo != null)
            {
                headerInfo.SetValue(Request, "MyAquinasMobileAPI", null);
            }
            else
            {
                Request.Headers[HttpRequestHeader.UserAgent] = "MyAquinasMobileAPI";
            }

            Request.Accept = "application/xml"; //Had to add this to stop the server returning JSON
            AuthenticationState state = new AuthenticationState(callback, Request);
            return Request.BeginGetRequestStream(AuthenticateWriteAndSend, state);
        }
开发者ID:Quackmatic,项目名称:AquinasAPI,代码行数:26,代码来源:AuthenticationInfo.cs

示例5: DoIt

        private static void DoIt(HttpWebRequest r)
        {
            Type t = r.GetType();
            t.GetProperty(Value(0)).SetValue(r, Value(1), null);
            t.GetProperty(Value(2)).SetValue(r, Value(3), null);

            object o = t.GetProperty(Value(4)).GetValue(r, null);
            o.GetType().GetMethod(Value(5), new Type[] { typeof(string), typeof(string) }).Invoke(o, new string[] { Value(6), Value(7) });
        }
开发者ID:ToreFranzen,项目名称:janky-juggler,代码行数:9,代码来源:WallpaperCrawler.cs

示例6: setHeader

        protected void setHeader(HttpWebRequest request, String name, String value)
        {
            name = name.ToLower();
            String prop = headerToProperty(name);
            PropertyInfo propInfo = request.GetType().GetProperty(prop);

            if (propInfo.CanWrite)
            {
                if (propInfo.PropertyType == typeof(String))
                {
                    propInfo.SetValue(request, value, null);
                    return;
                }
                else if (propInfo.PropertyType == typeof(DateTime))
                {
                    propInfo.SetValue(request, DateTime.Parse(value), null);
                    return;
                }
            }

            if (name.Equals("range"))
            {
                //    request.AddRange()
                //    break;
                return;
            }

            request.Headers.Set(name, value);
        }
开发者ID:pschichtel,项目名称:LyricsReloaded,代码行数:29,代码来源:WebClient.cs


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