本文整理汇总了C#中System.Net.HttpListenerResponse类的典型用法代码示例。如果您正苦于以下问题:C# HttpListenerResponse类的具体用法?C# HttpListenerResponse怎么用?C# HttpListenerResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpListenerResponse类属于System.Net命名空间,在下文中一共展示了HttpListenerResponse类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
开发者ID:andreasetti,项目名称:TestFirst.Net,代码行数:7,代码来源:SerializerRequestProcessor.cs
示例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;
}
开发者ID:SOACAt,项目名称:WebDAVSharp.Server,代码行数:13,代码来源:HttpListenerResponseAdapter.cs
示例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;
}
开发者ID:Winterleaf,项目名称:WebDAVSharp.Server,代码行数:13,代码来源:HttpListenerResponseAdapter.cs
示例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");
}
}
开发者ID:bizarrefish,项目名称:TestVisor,代码行数:29,代码来源:VMAgentServer.cs
示例5: Handle
public override object Handle(Project project, object body, HttpListenerResponse response)
{
return project
.GetVersions()
.OrderByDescending(v => v)
.FirstOrDefault();
}
开发者ID:Troposphir,项目名称:AtmoLauncher,代码行数:7,代码来源:GetVersion.cs
示例6: ResponseWrite
public static void ResponseWrite(HttpListenerResponse response, string content)
{
using (StreamWriter sw = new StreamWriter(response.OutputStream))
{
sw.Write(content);
}
}
开发者ID:imzjy,项目名称:MiniHttpServer,代码行数:7,代码来源:MiniUtility.cs
示例7: Response
public Response(HttpListenerResponse response, App app)
{
_response = response;
_writer = new StreamWriter(new BufferedStream(response.OutputStream));
App = app;
}
开发者ID:dfcook,项目名称:Express.NET,代码行数:7,代码来源:Response.cs
示例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 { }
}
}
开发者ID:FihlaTV,项目名称:conference,代码行数:29,代码来源:Server.cs
示例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);
}
}
开发者ID:spdr870,项目名称:SongRequest,代码行数:7,代码来源:FaviconHandler.cs
示例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();
}
开发者ID:LindaLawton,项目名称:google-api-dotnet-client,代码行数:32,代码来源:HttpListener.cs
示例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);
}
开发者ID:shaunstanislaus,项目名称:winappdriver,代码行数:31,代码来源:Server.cs
示例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();
}
开发者ID:radtek,项目名称:winmon,代码行数:34,代码来源:Server.cs
示例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);
}
开发者ID:nixxa,项目名称:HttpServer,代码行数:37,代码来源:GuestbookApplication.cs
示例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...");
}
开发者ID:badou119,项目名称:RemoteView,代码行数:35,代码来源:LeftClickPageHandler.cs
示例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];
}
开发者ID:badou119,项目名称:RemoteView,代码行数:13,代码来源:ScreenPageHandler.cs
示例16: RespondWithNotFound
private void RespondWithNotFound(HttpListenerRequest request, HttpListenerResponse response)
{
_log.DebugFormat("Responded with 404 Not Found for url {0}", request.Url);
response.StatusCode = 404;
response.StatusDescription = "Not Found";
response.OutputStream.Close();
}
开发者ID:MatteS75,项目名称:Qupla,代码行数:7,代码来源:WebServer.cs
示例17: WriteTo
public override void WriteTo(HttpListenerResponse resp)
{
base.WriteTo(resp);
FileStream fs = new FileStream(_file, FileMode.Open);
fs.CopyTo(resp.OutputStream);
fs.Close();
}
开发者ID:todd-x86,项目名称:sharpserver,代码行数:7,代码来源:FileResponse.cs
示例18: 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
示例19: PuppetProcessor
private static bool PuppetProcessor(HttpListenerRequest request, HttpListenerResponse response)
{
string content = null;
if (request.HttpMethod == "GET")
{
var contentId = request.QueryString.Count > 0 ? request.QueryString[0] : null;
if (string.IsNullOrEmpty(contentId) || !_contentStore.ContainsKey(contentId))
{
response.StatusCode = (int)HttpStatusCode.NotFound;
return false;
}
content = _contentStore[contentId]??"";
}
else
{
if (request.HasEntityBody)
{
using (var sr = new StreamReader(request.InputStream))
{
content = sr.ReadToEnd();
}
}
//response.ContentType = "application/json";
}
byte[] buf = Encoding.UTF8.GetBytes(content);
response.ContentLength64 = buf.Length;
response.OutputStream.Write(buf, 0, buf.Length);
return true;
}
开发者ID:cupidshen,项目名称:misc,代码行数:31,代码来源:Guider.cs
示例20: HandleGet
public void HandleGet(HttpListenerRequest request, HttpListenerResponse response)
{
string queryString = request.Url.Query;
var queryParts = Server.ParseQueryString(queryString);
string presetName = queryParts.GetFirstValue("preset");
if (string.IsNullOrEmpty(presetName))
{
response.StatusCode = 200;
response.WriteResponse(presets.GetAll());
}
else
{
string result = presets.Get(presetName);
if (result == null)
{
response.StatusCode = 404;
response.WriteResponse("No such preset has been registered");
}
else
{
response.StatusCode = 200;
response.WriteResponse(result);
}
}
}
开发者ID:cchamplin,项目名称:FFRest,代码行数:27,代码来源:PresetHandler.cs
注:本文中的System.Net.HttpListenerResponse类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论