C# Класс HttpServer.HttpResponse

Response that is sent back to the web browser / client.

A response can be sent if different ways. The easiest one is to just fill the Body stream with content, everything else will then be taken care of by the framework. The default content-type is text/html, you should change it if you send anything else.

The second and slightly more complex way is to send the response as parts. Start with sending the header using the SendHeaders method and then you can send the body using SendBody method, but do not forget to set ContentType and ContentLength before doing so.

Показать файл Открыть проект Примеры использования класса

Private Properties

Свойство Тип Описание
HttpResponse System

Открытые методы

Метод Описание
AddHeader ( string name, string value ) : void

Add another header to the document.

Adding any header will override the default ones and those specified by properties.

HttpResponse ( IHttpClientContext context, IHttpRequest request ) : System

Initializes a new instance of the IHttpResponse class.

Redirect ( Uri uri ) : void

Redirect client to somewhere else using the 302 status code.

You can not do anything more with the request when a redirect have been done. This should be your last action.

Redirect ( string url ) : void

redirect to somewhere

No body are allowed when doing redirects.

Send ( ) : void

Send headers and body to the browser.

SendBody ( byte buffer ) : void

Make sure that you have specified ContentLength and sent the headers first.

This method can be used if you want to send body contents without caching them first. This is recommended for larger files to keep the memory usage low.

SendBody ( byte buffer, int offset, int count ) : void

Make sure that you have specified ContentLength and sent the headers first.

This method can be used if you want to send body contents without caching them first. This is recommended for larger files to keep the memory usage low.

SendHeaders ( ) : void

Send headers to the client.

Приватные методы

Метод Описание
HttpResponse ( IHttpClientContext context, string httpVersion, ConnectionType connectionType ) : System

Initializes a new instance of the IHttpResponse class.

Описание методов

AddHeader() публичный Метод

Add another header to the document.
Adding any header will override the default ones and those specified by properties.
If headers already been sent. If value conditions have not been met.
public AddHeader ( string name, string value ) : void
name string Name of the header, case sensitive, use lower cases.
value string Header values can span over multiple lines as long as each line starts with a white space. New line chars should be \r\n
Результат void

HttpResponse() публичный Метод

Initializes a new instance of the IHttpResponse class.
public HttpResponse ( IHttpClientContext context, IHttpRequest request ) : System
context IHttpClientContext Client that send the .
request IHttpRequest Contains information of what the client want to receive.
Результат System

Redirect() публичный Метод

Redirect client to somewhere else using the 302 status code.
You can not do anything more with the request when a redirect have been done. This should be your last action.
If headers already been sent.
public Redirect ( Uri uri ) : void
uri System.Uri Destination of the redirect
Результат void

Redirect() публичный Метод

redirect to somewhere
No body are allowed when doing redirects.
public Redirect ( string url ) : void
url string where the redirect should go
Результат void

Send() публичный Метод

Send headers and body to the browser.
If content have already been sent.
public Send ( ) : void
Результат void

SendBody() публичный Метод

Make sure that you have specified ContentLength and sent the headers first.
This method can be used if you want to send body contents without caching them first. This is recommended for larger files to keep the memory usage low.
If headers have not been sent.
public SendBody ( byte buffer ) : void
buffer byte
Результат void

SendBody() публичный Метод

Make sure that you have specified ContentLength and sent the headers first.
This method can be used if you want to send body contents without caching them first. This is recommended for larger files to keep the memory usage low.
If headers have not been sent.
public SendBody ( byte buffer, int offset, int count ) : void
buffer byte
offset int offest of first byte to send
count int number of bytes to send.
Результат void

SendHeaders() публичный Метод

Send headers to the client.
If headers already been sent.
public SendHeaders ( ) : void
Результат void