public AddHeader ( string name, string value ) : void | ||
name | string | |
value | string | |
return | void |
using System.Net; HttpListenerContext context = listener.GetContext(); HttpListenerResponse response = context.Response; response.AddHeader("Content-Type", "text/html"); response.OutputStream.Write("Hello World!", 0, 12); response.Close();
using System.Net; HttpListenerContext context = listener.GetContext(); HttpListenerResponse response = context.Response; response.AddHeader("Set-Cookie", "name=value; Expires=Wed, 21 Oct 2022 07:28:00 GMT"); response.OutputStream.Write("Hello World!", 0, 12); response.Close();In this example, a Set-Cookie header is added to the response to set a cookie in the client's browser. The cookie will expire on October 21, 2022 at 7:28 AM GMT. The System.Net.HttpListenerResponse.AddHeader method is part of the System.Net namespace in the .NET Framework.