本文整理汇总了C#中System.Net.HttpListenerResponse类的典型用法代码示例。如果您正苦于以下问题:C# HttpListenerResponse类的具体用法?C# HttpListenerResponse怎么用?C# HttpListenerResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpListenerResponse类属于System.Net命名空间,在下文中一共展示了HttpListenerResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteResponseDto
private static void WriteResponseDto(HttpListenerResponse response, ISerializer serializer, MyDummyResponse responseDto)
{
using (var writer = new StreamWriter(response.OutputStream, Encoding.UTF8))
{
serializer.Serialize(writer, responseDto);
}
}
示例2: HttpListenerResponseAdapter
/// <summary>
/// Initializes a new instance of the <see cref="HttpListenerResponseAdapter" /> class.
/// </summary>
/// <param name="Response">The <see cref="HttpListenerResponse" /> to adapt for WebDAV#.</param>
/// <exception cref="System.ArgumentNullException">Response</exception>
/// <exception cref="ArgumentNullException"><paramref name="Response" /> is <c>null</c>.</exception>
public HttpListenerResponseAdapter(HttpListenerResponse Response)
{
if (Response == null)
throw new ArgumentNullException("Response");
_response = Response;
}
示例3: HttpListenerResponseAdapter
/// <summary>
/// Initializes a new instance of the <see cref="HttpListenerResponseAdapter" /> class.
/// </summary>
/// <param name="response">The <see cref="HttpListenerResponse" /> to adapt for WebDAV#.</param>
/// <exception cref="System.ArgumentNullException">Response</exception>
/// <exception cref="ArgumentNullException"><paramref name="response" /> is <c>null</c>.</exception>
public HttpListenerResponseAdapter(HttpListenerResponse response)
{
if (response == null)
throw new ArgumentNullException(nameof(response));
_response = response;
}
示例4: GetFileHandler
static void GetFileHandler(HttpListenerRequest request, HttpListenerResponse response)
{
var query = request.QueryString;
string targetLocation = query["target"];
Log ("GetFile: " + targetLocation + "...");
if(File.Exists(targetLocation))
{
try
{
using(var inStream = File.OpenRead(targetLocation))
{
response.StatusCode = 200;
response.ContentType = "application/octet-stream";
CopyStream(inStream, response.OutputStream);
}
}
catch(Exception e)
{
Log (e.Message);
response.StatusCode = 501;
}
}
else
{
response.StatusCode = 501;
Log ("File doesn't exist");
}
}
示例5: Handle
public override object Handle(Project project, object body, HttpListenerResponse response)
{
return project
.GetVersions()
.OrderByDescending(v => v)
.FirstOrDefault();
}
示例6: ResponseWrite
public static void ResponseWrite(HttpListenerResponse response, string content)
{
using (StreamWriter sw = new StreamWriter(response.OutputStream))
{
sw.Write(content);
}
}
示例7: Response
public Response(HttpListenerResponse response, App app)
{
_response = response;
_writer = new StreamWriter(new BufferedStream(response.OutputStream));
App = app;
}
示例8: RequestHandler
void RequestHandler(HttpListenerRequest req, HttpListenerResponse res)
{
Console.WriteLine("[RequestHandler: req.url=" + req.Url.ToString());
if (req.Url.AbsolutePath == "/cmd/record/start") {
Record.Start(req, res);
}
else if (req.Url.AbsolutePath == "/cmd/record/stop") {
Record.Stop(req, res);
}
else if (req.Url.AbsolutePath == "/cmd/livingcast/start") {
LivingCast.Start(req, res);
}
else if (req.Url.AbsolutePath == "/cmd/livingcast/stop") {
LivingCast.Stop(req, res);
}
else {
res.StatusCode = 404;
res.ContentType = "text/plain";
try
{
StreamWriter sw = new StreamWriter(res.OutputStream);
sw.WriteLine("NOT supported command: " + req.Url.AbsolutePath);
sw.Close();
}
catch { }
}
}
示例9: Process
public override void Process(HttpListenerRequest request, HttpListenerResponse response)
{
using (var stream = typeof(StaticHandler).Assembly.GetManifestResourceStream("SongRequest.Static.favicon.ico"))
{
stream.CopyTo(response.OutputStream);
}
}
示例10: SendHttpResponse
private void SendHttpResponse(TcpClient client, Stream stream, HttpListenerResponse response, byte[] body)
{
// Status line
var statusLine = $"HTTP/1.1 {response.StatusCode} {response.StatusDescription}\r\n";
var statusBytes = Encoding.ASCII.GetBytes(statusLine);
stream.Write(statusBytes, 0, statusBytes.Length);
// Headers
foreach (var key in response.Headers.AllKeys)
{
var value = response.Headers[key];
var line = $"{key}: {value}\r\n";
var lineBytes = Encoding.ASCII.GetBytes(line);
stream.Write(lineBytes, 0, lineBytes.Length);
}
// Content-Type header
var contentType = Encoding.ASCII.GetBytes($"Content-Type: {response.ContentType}\r\n");
stream.Write(contentType, 0, contentType.Length);
// Content-Length header
var contentLength = Encoding.ASCII.GetBytes($"Content-Length: {body.Length}\r\n");
stream.Write(contentLength, 0, contentLength.Length);
// "Connection: close", to tell the client we can't handle persistent TCP connections
var connection = Encoding.ASCII.GetBytes("Connection: close\r\n");
stream.Write(connection, 0, connection.Length);
// Blank line to indicate end of headers
stream.Write(new[] { (byte)'\r', (byte)'\n' }, 0, 2);
// Body
stream.Write(body, 0, body.Length);
stream.Flush();
// Graceful socket shutdown
client.Client.Shutdown(SocketShutdown.Both);
client.Dispose();
}
示例11: ResponseException
private void ResponseException(
string method, string path, Exception ex, ISession session, HttpListenerResponse response)
{
string body = null;
var httpStatus = HttpStatusCode.InternalServerError;
string contentType = "application/json";
if (ex is FailedCommandException)
{
var message = new Dictionary<string, object>
{
{ "sessionId", (session != null ? session.ID : null) },
{ "status", ((FailedCommandException)ex).Code },
{ "value", new Dictionary<string, object>
{
{ "message", ex.Message } // TODO stack trace
}
}
};
body = JsonConvert.SerializeObject(message);
}
else
{
httpStatus = HttpStatusCode.BadRequest;
contentType = "text/plain";
body = ex.ToString();
}
this.WriteResponse(response, httpStatus, contentType, body);
}
示例12: request_handler
private void request_handler(HttpListenerResponse handler_response, HttpListenerRequest handler_request)
{
string document = handler_request.RawUrl;
string docpath = root_path + document;
byte[] responsebyte;
if (File.Exists(docpath))
{
handler_response.StatusCode = (int)HttpStatusCode.OK;
handler_response.ContentType = "text/html";
responsebyte = File.ReadAllBytes(docpath);
}
else
{
if (debug)
{
handler_response.StatusCode = (int)HttpStatusCode.NotFound;
string responsestring = "Server running! ";
responsestring += "document: " + document + " ";
responsestring += "documentpath: " + docpath + " ";
responsestring += "root_path " + root_path + " ";
responsebyte = System.Text.Encoding.UTF8.GetBytes(responsestring);
}
else
{
handler_response.StatusCode = (int)HttpStatusCode.NotFound;
handler_response.ContentType = "text/html";
responsebyte = File.ReadAllBytes(root_path + "//error//error.html");
}
}
handler_response.ContentLength64 = responsebyte.Length;
System.IO.Stream output = handler_response.OutputStream;
output.Write(responsebyte, 0, responsebyte.Length);
output.Close();
}
示例13: Run
/// <summary>
/// Выполняет приложение
/// Для запросов GET возвращает все записи.
/// Для запросов POST создает и сохраняет новые записи.
/// </summary>
/// <param name="request">Request.</param>
/// <param name="response">Response.</param>
public override void Run(HttpListenerRequest request, HttpListenerResponse response)
{
if (request.HttpMethod == "POST")
{
if (request.HasEntityBody)
{
// читаем тело запроса
string data = null;
using (var reader = new StreamReader(request.InputStream))
{
data = reader.ReadToEnd ();
}
if (!string.IsNullOrWhiteSpace(data))
{
// формируем коллекцию параметров и их значений
Dictionary<string, string> requestParams = new Dictionary<string, string>();
string[] prms = data.Split('&');
for (int i = 0; i < prms.Length; i++)
{
string[] pair = prms[i].Split('=');
requestParams.Add(pair[0], Uri.UnescapeDataString(pair[1]).Replace('+',' '));
}
SaveEntry (GuestbookEntry.FromDictionary(requestParams));
}
response.Redirect(request.Url.ToString());
return;
}
}
DisplayGuestbook (response);
}
示例14: HandleRequest
/// <summary>
/// handle left clicks from client
/// </summary>
/// <param name="response"></param>
/// <param name="uri"></param>
/// <returns></returns>
public override byte[] HandleRequest(HttpListenerResponse response, string[] uri)
{
// must have 5 tokens
if (uri.Length != 7)
{
response.StatusCode = 400;
return BuildHTML("Error...");
}
int screen = GetRequestedScreenDevice(uri, screens);
bool error = handleMouseDown(uri, screen);
if (error)
{
// parameter error
response.StatusCode = 400;
return BuildHTML("Error...");
}
error = handleMouseUp(uri, screen);
if (error)
{
// parameter error
response.StatusCode = 400;
return BuildHTML("Error...");
}
return BuildHTML("Updating...");
}
示例15: HandleRequest
/// <summary>
/// Get a copy of the requested device screen image from cache
/// </summary>
/// <param name="response"></param>
/// <param name="uri"></param>
/// <returns></returns>
public override byte[] HandleRequest(HttpListenerResponse response, String[] uri)
{
int requested = GetRequestedScreenDevice(uri, screens);
lastScreenRequested = requested;
response.Headers.Set("Content-Type", "image/png");
return caches[requested];
}