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


C# HttpListenerResponse.AddHeader方法代码示例

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


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

示例1: ServeDirectoryListingAsync

		private static async Task ServeDirectoryListingAsync(DirectoryInfo root, DirectoryInfo directory, HttpListenerResponse response)
		{
			StringBuilder listBuilder = new StringBuilder();

			foreach (FileInfo file in directory.EnumerateFiles())
			{
				String target = directory.IsSameDirectory(root) ? file.Name
				                                                : Path.Combine(directory.Name, file.Name);
				listBuilder.AppendFormat("<li><a href=\"{0}\">{1}</a></li>", target, file.Name);
			}

			foreach (DirectoryInfo subDirectory in directory.EnumerateDirectories())
			{
				String target = directory.IsSameDirectory(root) ? subDirectory.Name
				                                                : Path.Combine(directory.Name, subDirectory.Name);
				listBuilder.AppendFormat("<li><a href=\"{0}\">{1}</a></li>", target, subDirectory.Name);
			}

			String htmlResponse = String.Format("<ul>{0}</ul>", listBuilder.ToString());

			response.ContentType = "text/html";
			response.ContentLength64 = htmlResponse.Length;
			response.AddHeader("Date", DateTime.Now.ToString("r"));

			response.StatusCode = (Int32)HttpStatusCode.OK; // Must be set before writing to OutputStream.

			using (StreamWriter writer = new StreamWriter(response.OutputStream))
			{
				await writer.WriteAsync(htmlResponse).ConfigureAwait(false);
			}
		}
开发者ID:piedar,项目名称:Hushpuppy,代码行数:31,代码来源:DirectoryListingService.cs

示例2: Map

 public void Map(Response response, HttpListenerResponse result)
 {
     result.StatusCode = response.StatusCode;
     response.Headers.ToList().ForEach(pair => result.AddHeader(pair.Key, pair.Value));
     if (response.Body != null)
     {
         var content = Encoding.UTF8.GetBytes(response.Body);
         result.OutputStream.Write(content, 0, content.Length);
     }
 }
开发者ID:jbuiss0n,项目名称:mock4net,代码行数:10,代码来源:HttpListenerResponseMapper.cs

示例3: PrepareOutputStream

 /*
  * Prepare Output Stream, using gzip if supported */
 protected Stream PrepareOutputStream(HttpListenerRequest request, HttpListenerResponse response)
 {
     string accept = request.Headers.Get("Accept-Encoding");
     Stream outputStream = response.OutputStream;
     if (accept != null && accept.Contains("gzip"))
     {
         response.AddHeader("Content-Encoding", "gzip");
         outputStream = new GZipStream(response.OutputStream, CompressionMode.Compress);
     }
     return outputStream;
 }
开发者ID:JohnathonReasons,项目名称:runuo-vendor-search,代码行数:13,代码来源:Handler.cs

示例4: ResponseText

        public static async Task ResponseText(HttpListenerResponse response, string localFilePath, string contentType)
        {
            var text = File.ReadAllText(localFilePath);

            response.ContentType = contentType;
            response.ContentEncoding = Encoding.UTF8;
            response.AddHeader("Charset", Encoding.UTF8.WebName);

            var textBytes = Encoding.UTF8.GetBytes(text);
            response.ContentLength64 = textBytes.LongLength;
            await response.OutputStream.WriteAsync(textBytes, 0, textBytes.Length);
        }
开发者ID:tommyinb,项目名称:SimpleFileServer,代码行数:12,代码来源:GetFileResponse.cs

示例5: deserializeResponse

 public static void deserializeResponse(string response, HttpListenerResponse originalResponse)
 {
     var headerResponse = JsonConvert.DeserializeObject<HeaderRespons> (response);
     if (relayIdSet.Contains (headerResponse.rid))
         relayIdSet.Remove (headerResponse.rid);
     originalResponse.StatusCode = headerResponse.statusCode;
     foreach (var h in headerResponse.headers) {
         if (HeaderUtil.isEndToEndHeader (h.Key))
             originalResponse.AddHeader (h.Key, h.Value);
     }
     //originalResponse.OutputStream.Write (headerResponse.body, 0, headerResponse.body.Length);
 }
开发者ID:funsu,项目名称:Wormhole,代码行数:12,代码来源:HeaderSerializer.cs

示例6: PrepareContext

        void PrepareContext(HttpListenerResponse tragetRsp, HttpWebResponse sourceRsp)
        {
            tragetRsp.ContentEncoding = Encoding.GetEncoding(sourceRsp.CharacterSet);
            tragetRsp.ContentType = sourceRsp.ContentType;

            foreach (string k in sourceRsp.Headers)
                foreach (string v in sourceRsp.Headers.GetValues(k))
                {
                    if (string.Equals(k, "Content-Length", StringComparison.OrdinalIgnoreCase))
                        continue;

                    tragetRsp.AddHeader(k, v);
                }
        }
开发者ID:alexf2,项目名称:ReactiveWebServerProto,代码行数:14,代码来源:ProxyHandler.cs

示例7: SendResponse

 public static void SendResponse(HttpListenerResponse response, string pluginName, string content)
 {
     CoreManager.ServerCore.GetStandardOut().PrintDebug("WebAdmin Response [" + pluginName + "]: " + content);
     byte[] buffer = Encoding.UTF8.GetBytes(content);
     response.StatusCode = (int) HttpStatusCode.OK;
     response.StatusDescription = "OK";
     response.ContentType = "text/html; charset=UTF-8";
     response.ContentLength64 = buffer.Length;
     response.ContentEncoding = Encoding.UTF8;
     response.AddHeader("plugin-name", pluginName);
     response.OutputStream.Write(buffer, 0, buffer.Length);
     response.OutputStream.Close();
     response.Close();
 }
开发者ID:habb0,项目名称:IHI,代码行数:14,代码来源:WebAdminManager.cs

示例8: SendResponse

        public void SendResponse(HttpListenerRequest request, HttpListenerResponse response)
        {
            var stream = new FileLoader(request.Url.AbsolutePath).LoadStream();

            response.ContentLength64 = stream.Length;
            response.SendChunked = false;
            response.ContentType = request.ContentType;
            response.AddHeader("Content-disposition", "attachment; filename=" + request.RawUrl.Remove(0, 1));

            writeTo(stream, response.OutputStream);

            response.StatusCode = (int)HttpStatusCode.OK;
            response.StatusDescription = "OK";

            stream.Close();
            response.Close();

            Console.WriteLine("200");
        }
开发者ID:Boberneprotiv,项目名称:FileService,代码行数:19,代码来源:FileRequest.cs

示例9: ConvertNancyResponseToResponse

        private static void ConvertNancyResponseToResponse(Response nancyResponse, HttpListenerResponse response)
        {
            foreach (var header in nancyResponse.Headers)
            {
                response.AddHeader(header.Key, header.Value);
            }

            foreach (var nancyCookie in nancyResponse.Cookies)
            {
                response.Cookies.Add(ConvertCookie(nancyCookie));
            }

            response.ContentType = nancyResponse.ContentType;
            response.StatusCode = (int)nancyResponse.StatusCode;

            using (var output = response.OutputStream)
            {
                nancyResponse.Contents.Invoke(output);
            }
        }
开发者ID:thedersen,项目名称:Nancy,代码行数:20,代码来源:NancyHost.cs

示例10: SaveInfo

        public Ansver SaveInfo(HttpListenerRequest request, HttpListenerResponse response)
        {
            Stream inputStream = request.InputStream;
            Console.WriteLine("������ ����������� �����������");

            Console.WriteLine("���������� ������ �� ������:");
            string result = "";
            int last;
            string uriPath = request.Url.AbsolutePath.Split('/')[2];
            try
            {
                byte[] ansver = new byte[request.ContentLength64];
                request.InputStream.Read(ansver, 0, (int)request.ContentLength64);
                result = Encoding.UTF8.GetString(ansver);
                Console.WriteLine(result);

                Directory.CreateDirectory(path + uriPath);
                List<string> allfiles = new List<string>(Directory.GetFiles(path + uriPath, "*.txt"));
                allfiles.Sort();
                last = this.GetLast(allfiles);
                StreamWriter writer = new StreamWriter(path + uriPath + "/" + (last).ToString() + ".txt",false, Encoding.UTF8);

                writer.Write(result);
                Console.WriteLine("������ ���������.");
                writer.Close();
                response.AddHeader("id", last.ToString());
                response.StatusCode = (int) HttpStatusCode.Created;
                return new Ansver(null, response);

            }
            catch (Exception exception)
            {
                Console.WriteLine("������ ����������, ��������� ������: " + exception.Message);
                response.StatusCode = (int) HttpStatusCode.InternalServerError;
                return new Ansver(null, response);
            }
        }
开发者ID:Cybermar95,项目名称:SummerProj,代码行数:37,代码来源:Saver.cs

示例11: ConvertNancyResponseToResponse

        private void ConvertNancyResponseToResponse(Response nancyResponse, HttpListenerResponse response)
        {
            foreach (var header in nancyResponse.Headers)
            {
                response.AddHeader(header.Key, header.Value);
            }

            foreach (var nancyCookie in nancyResponse.Cookies)
            {
                response.Headers.Add(HttpResponseHeader.SetCookie, nancyCookie.ToString());
            }

            if (nancyResponse.ReasonPhrase != null)
            {
                response.StatusDescription = nancyResponse.ReasonPhrase;
            }

            if (nancyResponse.ContentType != null)
            {
                response.ContentType = nancyResponse.ContentType;
            }

            response.StatusCode = (int)nancyResponse.StatusCode;

            if (configuration.AllowChunkedEncoding)
            {
                OutputWithDefaultTransferEncoding(nancyResponse, response);
            }
            else
            {
                OutputWithContentLength(nancyResponse, response);
            }
        }
开发者ID:jmcota,项目名称:Nancy,代码行数:33,代码来源:NancyHost.cs

示例12: Exception

		void Exception (HttpListenerResponse response, Exception exception)
		{
			var id = CreateExceptionId ();
			exceptions [id] = exception;
			response.AddHeader (ExceptionHeaderName, id.ToString ());
			if (exception == null)
				return;
			response.StatusCode = 500;
			using (var writer = new StreamWriter (response.OutputStream)) {
				writer.WriteLine (string.Format ("EXCEPTION: {0}", exception));
			}
			response.Close ();
		}
开发者ID:RafasTavares,项目名称:mac-samples,代码行数:13,代码来源:Server.cs

示例13: ServeFile

		static bool ServeFile(string path, HttpListenerResponse httpResponse)
		{		
			if(!File.Exists(path))
			{
				return false;
			}

			// http://stackoverflow.com/a/13386573/4264
			using(var fs = File.OpenRead(path))
			{
				httpResponse.StatusCode = (int)HttpStatusCode.OK;
				httpResponse.ContentLength64 = fs.Length;
				httpResponse.SendChunked = false;
				httpResponse.ContentType = GetContentType(Path.GetExtension(path));

				if(httpResponse.ContentType == "application/octet-stream")
				{
					httpResponse.AddHeader("Content-disposition", "attachment; filename=" +
						Path.GetFileName(path));
				}

				byte[] buffer = new byte[64 * 1024];
				int read;
				using(BinaryWriter bw = new BinaryWriter(httpResponse.OutputStream))
				{
					while((read = fs.Read(buffer, 0, buffer.Length)) > 0)
					{
						bw.Write(buffer, 0, read);
						bw.Flush(); //seems to have no effect
					}
				}
			}

			return true;
		}
开发者ID:knocte,项目名称:Sfx.Mvc,代码行数:35,代码来源:HttpServer.cs

示例14: SendZippedResponse

        public void SendZippedResponse(HttpListenerResponse response, ByteResponseData data)
        {
            response.AddHeader("Content-Encoding", "gzip");
            response.ContentType = data.ContentType.GetValue();
            byte[] buffer = data.Content;
            using (MemoryStream ms = new MemoryStream())
            {
                using (GZipStream zip = new GZipStream(ms, CompressionMode.Compress))
                {
                    zip.Write(buffer, 0, buffer.Length);
                }
                buffer = ms.ToArray();
            }

            WriteAndFlushResponse(response, buffer);
        }
开发者ID:cannero,项目名称:restlib,代码行数:16,代码来源:ResponseWriter.cs

示例15: ProcessRequest

		private void ProcessRequest(HttpListenerRequest request, HttpListenerResponse response)
		{
			response.AddHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0");
			response.AddHeader("Pragma", "no-cache");

			IRequestHandler handler = AssignRequestHandler(request);

			if (handler != null)
			{
				handler.Process(request, response);
			}
			else
			{
				FinalizeIgnoredResponse(response, 404, "Resource Not Found");
			}
		}
开发者ID:Philo,项目名称:Revalee,代码行数:16,代码来源:RequestManager.cs


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