⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 csrequest.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 CS
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.IO;
using System.Text;
using System.Net;
using System.Web;

namespace CommunityServer.Components
{
	public  class CSRequest 
	{
		private const int defaultTimeout_ = 60000;
		private static string referer_ = "Community Server";
		private static readonly string userAgent_ = SiteStatistics.CommunityServerVersion
			+ " (" + Environment.OSVersion.ToString() + "; .NET CLR " + Environment.Version.ToString() + ")";


        /// <summary>
        /// Creates a new HttpRequest with the default Referral value
        /// </summary>
		public static HttpWebRequest CreateRequest(string url) 
		{
			return CreateRequest(url,referer_);
		}

		/// <summary>
		/// Creates a new HttpRequest and sets the referral value.
		/// </summary>
		public static HttpWebRequest CreateRequest(string url, string referral) 
		{
			WebRequest req = WebRequest.Create(url);
			
			HttpWebRequest wreq = req as HttpWebRequest;
			if (null != wreq) 
			{
				wreq.UserAgent = userAgent_;
				wreq.Referer =  referral;
				wreq.Timeout = defaultTimeout_;
			}
			return wreq;
		}	

        /// <summary>
        /// Gets the HttpResponse using the default referral
        /// </summary>
		public static HttpWebResponse GetResponse(string url)
		{
			return GetResponse(url,referer_);
		}

        /// <summary>
        /// Gets the HttpResponse using the supplied referral
        /// </summary>
		public static HttpWebResponse GetResponse(string url, string referral)
		{
			HttpWebRequest request = CreateRequest(url,referral);
			return (HttpWebResponse)request.GetResponse() ;
		}		

        /// <summary>
        /// Gets the full text at the url parameter
        /// </summary>
		public static string GetPageText(string url)
		{
			return GetPageText(url,referer_);
		}

        /// <summary>
        /// Gets the full text at the url parameter
        /// </summary>
		public static string GetPageText(string url, string referral)
		{
			HttpWebResponse response = GetResponse(url,referral);
			using (Stream s = response.GetResponseStream())
			{
				string enc = response.ContentEncoding.Trim() ;
				if ( enc == "" )
					enc = "us-ascii" ;
				Encoding encode = System.Text.Encoding.GetEncoding(enc);
				using ( StreamReader sr = new StreamReader( s, encode ) )
				{
					return sr.ReadToEnd() ;
				}
			}
		}
		
		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -