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


C# HttpWorkerRequest.GetKnownRequestHeader方法代码示例

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


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

示例1: RequestStream

		public RequestStream(HttpWorkerRequest request)
		{
			this.request = request;

			tempBuff = request.GetPreloadedEntityBody();

            _contentLength = long.Parse(request.GetKnownRequestHeader(HttpWorkerRequest.HeaderContentLength));
            
            // Handle the case where GetPreloadedEntityBody is null -- e.g. Mono
			if (tempBuff == null || tempBuff.Length == 0)
			{
				isInPreloaded = false;
			}
    	}
开发者ID:codingbat,项目名称:BandCamp,代码行数:14,代码来源:RequestStream.cs

示例2: AsyncUpload

        public AsyncUpload(HttpWorkerRequest wRquest)
        {
            if (wRquest == null) throw new ArgumentNullException("wRquest");
            this.uploadProcess = new UploadProcess(delegate(float f) { });
            workerRequest = wRquest;

            //当前读到的流长度
            this.preLen = workerRequest.GetPreloadedEntityBodyLength();
            //请求流的总长度
            this.totLen = workerRequest.GetTotalEntityBodyLength();
            //内容分隔符 如: -----------------------------152733254716788
            if (preLen == 0 && workerRequest.IsClientConnected() && workerRequest.HasEntityBody())
            {
                byte[] buffer = new byte[8192];
                preLen = workerRequest.ReadEntityBody(buffer, buffer.Length);
                byte[] buf = new byte[preLen];
                for (int i = 0; i < buf.Length; i++) buf[i] = buffer[i];
                this.perBodyBytes = buf;
            }
            else
                this.perBodyBytes = workerRequest.GetPreloadedEntityBody();

            this.headerBytes = this.GetBoundaryBytes(Encoding.UTF8.GetBytes(workerRequest.GetKnownRequestHeader(HttpWorkerRequest.HeaderContentType)));
            //请求流尾部分隔符 如: -----------------------------152733254716788--
            this.contentEnd = new byte[this.headerBytes.Length + 2];
            this.headerBytes.CopyTo(this.contentEnd, 0);
            this.contentEnd[this.headerBytes.Length] = 45;
            this.contentEnd[this.headerBytes.Length + 1] = 45;

            //当前流中第一个文件分隔符的位置
            int fHeaderPosition = perBodyBytes.Indexof(fileNameHeader);
            //尝试在已读取到的流中找文件尾位置
            this.fEndPosition = perBodyBytes.Indexof(contentEnd);
            if (fHeaderPosition > -1)
            {
                //先找到文件名
                IList<byte> bufList = new List<byte>();
                int i = fHeaderPosition + fileNameHeader.Length;
                while (i < perBodyBytes.Length)
                {
                    if (perBodyBytes[i] == 34) break;
                    bufList.Add(perBodyBytes[i]);
                    i++;
                }

                this.FileName = Encoding.UTF8.GetString(bufList.ToArray());//file name
                this.fPosition = perBodyBytes.Indexof(wrapBytes, i) + 4;//当前流中此文件的开始位置
                this.FileLength = this.totLen - this.fPosition;
            }
        }
开发者ID:hanwest00,项目名称:MYTestWeb,代码行数:50,代码来源:AsyncUpload.cs

示例3: Redirect

		static void Redirect (HttpWorkerRequest wr, string location)
		{
			string host = wr.GetKnownRequestHeader (HttpWorkerRequest.HeaderHost);
			wr.SendStatus (301, "Moved Permanently");
			wr.SendUnknownResponseHeader ("Connection", "close");
			wr.SendUnknownResponseHeader ("Date", DateTime.Now.ToUniversalTime ().ToString ("r"));
			wr.SendUnknownResponseHeader ("Location", String.Format ("{0}://{1}{2}", wr.GetProtocol(), host, location));
			Encoding enc = Encoding.ASCII;
			wr.SendUnknownResponseHeader ("Content-Type", "text/html; charset=" + enc.WebName);
			string content = String.Format (CONTENT301, host, location);
			byte [] contentBytes = enc.GetBytes (content);
			wr.SendUnknownResponseHeader ("Content-Length", contentBytes.Length.ToString ());
			wr.SendResponseFromMemory (contentBytes, contentBytes.Length);
			wr.FlushResponse (true);
			wr.CloseConnection ();
		}
开发者ID:louislatreille,项目名称:xsp,代码行数:16,代码来源:ApplicationHost.cs

示例4: IsSameOriginRequest

        // Determines whether or not a given HttpWorkerRequest meets the requirements for "same-origin"
        // as called out in these two documents:
        // - http://tools.ietf.org/html/rfc6454 (Web Origin)
        // - http://tools.ietf.org/html/rfc6455 (WebSockets)
        public static bool IsSameOriginRequest(HttpWorkerRequest workerRequest) {
            string hostHeader = workerRequest.GetKnownRequestHeader(HttpWorkerRequest.HeaderHost);
            if (String.IsNullOrEmpty(hostHeader)) {
                // RFC 6455 (Sec. 4.1) and RFC 2616 (Sec. 14.23) make the "Host" header mandatory
                return false;
            }

            string secWebSocketOriginHeader = workerRequest.GetUnknownRequestHeader("Origin");
            if (String.IsNullOrEmpty(secWebSocketOriginHeader)) {
                // RFC 6455 (Sec. 4.1) makes the "Origin" header mandatory for browser clients.
                // Phone apps, console clients, and similar non-browser clients aren't required to send the header,
                // but this method isn't intended for those use cases anyway, so we can fail them. (Note: it's still
                // possible for a non-browser app to send the appropriate Origin header.)
                return false;
            }

            // create URI instances from both the "Host" and the "Origin" headers
            Uri hostHeaderUri = null;
            Uri originHeaderUri = null;
            bool urisCreatedSuccessfully = Uri.TryCreate(workerRequest.GetProtocol() + "://" + hostHeader.Trim(), UriKind.Absolute, out hostHeaderUri) // RFC 2616 (Sec. 14.23): "Host" header doesn't contain the scheme, so we need to prepend
                && Uri.TryCreate(secWebSocketOriginHeader.Trim(), UriKind.Absolute, out originHeaderUri);

            if (!urisCreatedSuccessfully) {
                // construction of one of the Uri instances failed
                return false;
            }

            // RFC 6454 (Sec. 4), schemes must be normalized to lowercase. (And for WebSockets we only
            // support HTTP / HTTPS anyway.)
            if (originHeaderUri.Scheme != "http" && originHeaderUri.Scheme != "https") {
                return false;
            }

            // RFC 6454 (Sec. 5), comparisons should be ordinal. The Uri class will automatically
            // fill in the Port property using the default value for the scheme if the provided input doesn't
            // explicitly contain a port number.
            return hostHeaderUri.Scheme == originHeaderUri.Scheme
                && hostHeaderUri.Host == originHeaderUri.Host
                && hostHeaderUri.Port == originHeaderUri.Port;
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:44,代码来源:WebSocketUtil.cs

示例5: Fill

		string Fill (HttpWorkerRequest wr, bool standard)
		{
			StringBuilder sb = new StringBuilder ();
			
			for (int i = 0; i < HttpWorkerRequest.RequestHeaderMaximum; i++){
				string val = wr.GetKnownRequestHeader (i);
				if (val == null || val == "")
					continue;
				string key = HttpWorkerRequest.GetKnownRequestHeaderName (i);
				AppendKeyValue (sb, key, val, standard);
			}
			string [][] other = wr.GetUnknownRequestHeaders ();
			if (other == null)
				return sb.ToString ();

			for (int i = other.Length; i > 0; ){
				i--;
				AppendKeyValue (sb, other [i][0], other [i][1], standard);
			}

			return sb.ToString ();
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:22,代码来源:ServerVariablesCollection.cs

示例6: SetByteMarkers

 private void SetByteMarkers(HttpWorkerRequest workerRequest, Encoding encoding)
 {
     var contentType = workerRequest.GetKnownRequestHeader(HttpWorkerRequest.HeaderContentType);
     var bufferIndex = contentType.IndexOf("boundary=") + "boundary=".Length;
     var boundary = String.Concat("--", contentType.Substring(bufferIndex));
     _boundaryBytes = encoding.GetBytes(string.Concat(boundary, _lineBreak));
     //head 结尾标志 (假定!hack,不同的表单或许会不一样的)
     _endFileHeaderBytes = encoding.GetBytes(string.Concat("application/octet-stream"+_lineBreak, _lineBreak));
     _endHeaderBytes = encoding.GetBytes(string.Concat(_lineBreak, _lineBreak));
     //文件结尾标志
    // _endFileBytes = encoding.GetBytes(string.Concat(_lineBreak, boundary, "--", _lineBreak));
    _endFileBytes = encoding.GetBytes(string.Concat(_lineBreak, boundary, "--"));
    
     _lineBreakBytes = encoding.GetBytes(string.Concat(_lineBreak + boundary + _lineBreak));
 }
开发者ID:chenkaibin,项目名称:FileStation,代码行数:15,代码来源:UploadProcessor2.cs

示例7: Application_ResolveRequestCache

 void Application_ResolveRequestCache(object sender, EventArgs e)
 {
     wr = GetCurrentWorkerRequest();
     string contentTypeHeader = wr.GetKnownRequestHeader(HttpWorkerRequest.HeaderContentType);
     if (contentTypeHeader != null && contentTypeHeader.ToLower().StartsWith("multipart/form-data"))
     {
         WaitForUploadToComplete();
     }
 }
开发者ID:starlightliu,项目名称:Starlightliu,代码行数:9,代码来源:FileUploadModule.cs

示例8: IsUpload

 internal static bool IsUpload(HttpWorkerRequest request)
 {
     string contentType = request.GetKnownRequestHeader(HttpWorkerRequest.HeaderContentType);
     return IsPost(request) && IsMultiPartFormData(contentType) && HasBoundary(contentType);
 }
开发者ID:Inzaghi2012,项目名称:teamlab.v7.5,代码行数:5,代码来源:UploadProgressUtils.cs

示例9: AddHeaderVariables

		void AddHeaderVariables (HttpWorkerRequest wr)
		{
			string hname;
			string hvalue;

			// Add all known headers
			for (int i = 0; i < HttpWorkerRequest.RequestHeaderMaximum; i++) {
				hvalue = wr.GetKnownRequestHeader (i);
				if (null != hvalue && hvalue.Length > 0) {
					hname = HttpWorkerRequest.GetKnownRequestHeaderName (i);
					if (null != hname && hname.Length > 0)
						Add ("HTTP_" + hname.ToUpper (Helpers.InvariantCulture).Replace ('-', '_'), hvalue);
				}
			}

			// Get all other headers
			string [][] unknown = wr.GetUnknownRequestHeaders ();
			if (null != unknown) {
				for (int i = 0; i < unknown.Length; i++) {
					hname = unknown [i][0];
					if (hname == null)
						continue;
					hvalue = unknown [i][1];
					Add ("HTTP_" + hname.ToUpper (Helpers.InvariantCulture).Replace ('-', '_'), hvalue);
				}
			}
		}
开发者ID:nlhepler,项目名称:mono,代码行数:27,代码来源:ServerVariablesCollection.cs

示例10: GetEncodingFromHeaders

        public static Encoding GetEncodingFromHeaders(HttpWorkerRequest workerRequest)
        {
            if (workerRequest == null)
                throw new ArgumentNullException("workerRequest");

            string userAgent = workerRequest.GetKnownRequestHeader(HttpWorkerRequest.HeaderUserAgent);
            if (userAgent != null && CultureInfo.InvariantCulture.CompareInfo.IsPrefix(userAgent, "UP"))
            {
                string text = workerRequest.GetUnknownRequestHeader("x-up-devcap-post-charset");
                if (!string.IsNullOrEmpty(text))
                {
                    try
                    {
                        return Encoding.GetEncoding(text);
                    }
                    catch
                    {
                    }
                }
            }
            if (!workerRequest.HasEntityBody())
            {
                return null;
            }
            string contentType = workerRequest.GetKnownRequestHeader(HttpWorkerRequest.HeaderContentType);
            if (contentType == null)
            {
                return null;
            }
            string attributeFromHeader = GetAttributeFromHeader(contentType, "charset");
            if (attributeFromHeader == null)
            {
                return null;
            }
            Encoding result = null;
            try
            {
                result = Encoding.GetEncoding(attributeFromHeader);
            }
            catch
            {
            }
            return result;
        }
开发者ID:cloudguy,项目名称:Storage-Monster,代码行数:44,代码来源:MultipartFormHelper.cs

示例11: GetMultipartBoundary

        public static byte[] GetMultipartBoundary(HttpWorkerRequest workerRequest)
        {
            if (workerRequest == null)
                throw new ArgumentNullException("workerRequest");

            string text = workerRequest.GetKnownRequestHeader(HttpWorkerRequest.HeaderContentType);
            if (text == null)
                return null;

            text = GetAttributeFromHeader(text, "boundary");
            if (text == null)
                return null;

            text = "--" + text;
            return Encoding.ASCII.GetBytes(text.ToCharArray());
        }
开发者ID:cloudguy,项目名称:Storage-Monster,代码行数:16,代码来源:MultipartFormHelper.cs

示例12: UploadHttpRequest

        internal UploadHttpRequest(HttpContext context)
        {
            _request = context.Request;
            _worker = GetWorkerRequest(context);

            // TODO: should we silently ignore?
            if (_worker == null)
                throw new HttpException("Could not intercept worker.");

            string fileSizeHeader = _worker.GetUnknownRequestHeader("X-File-Size");

            if (string.IsNullOrEmpty(fileSizeHeader) || !long.TryParse(fileSizeHeader, out _contentLength))
                _contentLength = long.Parse(_worker.GetKnownRequestHeader(HttpWorkerRequest.HeaderContentLength));
        }
开发者ID:codingbat,项目名称:BandCamp,代码行数:14,代码来源:UploadHttpRequest.cs

示例13: Log

        public static void Log(HttpWorkerRequest worker, string uploadId)
        {
#if DEBUG
            Log(" - Content-Length:" + worker.GetKnownRequestHeader(System.Web.HttpWorkerRequest.HeaderContentLength), uploadId);
#endif
        }
开发者ID:codingbat,项目名称:BandCamp,代码行数:6,代码来源:SimpleLogger.cs

示例14: SetByteMarkers

        private void SetByteMarkers(HttpWorkerRequest workerRequest, Encoding encoding)
        {
            var contentType = workerRequest.GetKnownRequestHeader(HttpWorkerRequest.HeaderContentType);
            var bufferIndex = contentType.IndexOf("boundary=") + "boundary=".Length;
            var boundary = String.Concat("--", contentType.Substring(bufferIndex));

            _boundaryBytes = encoding.GetBytes(string.Concat(boundary, _lineBreak));
            _endHeaderBytes = encoding.GetBytes(string.Concat(_lineBreak, _lineBreak));
            _endFileBytes = encoding.GetBytes(string.Concat(_lineBreak, boundary, "--", _lineBreak));
            _lineBreakBytes = encoding.GetBytes(string.Concat(_lineBreak + boundary + _lineBreak));
        }
开发者ID:cloudguy,项目名称:Storage-Monster,代码行数:11,代码来源:LargeFileUploadHttpModule.cs


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