本文整理汇总了C#中System.Net.HttpListenerResponse.Close方法的典型用法代码示例。如果您正苦于以下问题:C# HttpListenerResponse.Close方法的具体用法?C# HttpListenerResponse.Close怎么用?C# HttpListenerResponse.Close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.HttpListenerResponse
的用法示例。
在下文中一共展示了HttpListenerResponse.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
public void Process(HttpListenerRequest request, HttpListenerResponse response)
{
try
{
if (request.HttpMethod != "GET")
{
response.StatusCode = 405;
response.StatusDescription = "Method Not Supported";
response.Close();
return;
}
string version = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion;
string status = GetStatusDescription();
string timestamp = DateTime.UtcNow.ToString("s", CultureInfo.InvariantCulture) + "Z";
FormatJsonResponse(response, version, status, timestamp);
}
catch (HttpListenerException hlex)
{
Supervisor.LogException(hlex, TraceEventType.Error, request.RawUrl);
response.StatusCode = 500;
response.StatusDescription = "Error Occurred";
response.Close();
}
}
示例2: SendResponse
public static void SendResponse(HttpListenerResponse response, byte[] buffer)
{
response.ContentLength64 = buffer.Length;
response.OutputStream.Write(buffer, 0, buffer.Length);
response.OutputStream.Close();
response.Close();
}
示例3: SendResponse
public static void SendResponse(HttpListenerResponse response, string str)
{
var result = Encoding.UTF8.GetBytes(str);
response.ContentLength64 = result.Length;
response.OutputStream.Write(result, 0, result.Count());
response.Close();
}
示例4: SendResponse
public static void SendResponse(HttpListenerResponse response, string 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.OutputStream.Write(buffer, 0, buffer.Length);
response.OutputStream.Close();
response.Close();
}
示例5: authenticate
public void authenticate(HttpListenerRequest req, HttpListenerResponse res, HTTPSession session)
{
// use the session object to store state between requests
session["nonce"] = RandomString();
session["state"] = RandomString();
// TODO make authentication request
// TODO insert the redirect URL
string login_url = null;
res.Redirect(login_url);
res.Close();
}
示例6: 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();
}
示例7: 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");
}
示例8: UpdateEmployee
private void UpdateEmployee(HttpListenerRequest request, HttpListenerResponse response)
{
// Deserialize Employee object.
string body = String.Empty;
using (StreamReader reader = new StreamReader(request.InputStream))
{
body = reader.ReadToEnd();
}
Employee employee = null;
try
{
if (_dataFormat == "application/xml")
{
employee = UtilityXml.DeserializeXml<Employee>(body);
}
else if (_dataFormat == "application/json")
{
employee = UtilityJson.DeserializeJson<Employee>(body);
}
}
catch (Exception ex)
{
Console.WriteLine(@"ERROR: Failed to deserialize the Employee object - {ex.Message}");
}
if (employee == null)
{
response.StatusCode = 400;
response.Close();
return;
}
// Perform the actual update.
_repository.Update(employee);
// Construct and send the response.
response.StatusCode = 200;
response.Close();
Console.WriteLine(@"POST: Updated employee with ID {employee.EmployeeId}");
}
示例9: OnGetRequest
public override void OnGetRequest(HttpListenerRequest request, HttpListenerResponse response)
{
string url = request.Url.ToString().Remove(0, host.Length - 1);
if (url.Contains("?v")) {
url = url.Substring(0, url.IndexOf("?v"));
}
string filename = AssetPath + url;
string responseString = string.Empty;
if (url.EndsWith("/")) {
responseString = "<html><body><h1>SimpleFramework WebServer 0.1.0</h1>";
responseString += "Current Time: " + DateTime.Now.ToString() + "<br>";
responseString += "url : " + request.Url + "<br>";
responseString += "Asset Path: " + filename;
goto label;
} else {
if (File.Exists(filename)) {
using (Stream fs = File.Open(filename, FileMode.Open)) {
response.ContentLength64 = fs.Length;
response.ContentType = GetMimeType(filename) + "; charset=UTF-8";
fs.CopyTo(response.OutputStream);
response.OutputStream.Flush();
response.Close(); return;
}
} else {
responseString = "<h1>404</h1>";
goto label;
}
}
label:
try {
response.ContentLength64 = Encoding.UTF8.GetByteCount(responseString);
response.ContentType = "text/html; charset=UTF-8";
} finally {
Stream output = response.OutputStream;
StreamWriter writer = new StreamWriter(output);
writer.Write(responseString);
writer.Close();
}
}
示例10: OnBeginGetContextReceived
private HttpListener OnBeginGetContextReceived(IAsyncResult result)
{
if (_response != null)
{
try
{
_response.Close();
_response = null;
}
catch
{ }
}
var context = _listener.EndGetContext(result);
var request = context.Request;
var url = request.Url;
//Console.WriteLine("streaming request: " + request.Url);
lock (_gate)
{
_response = context.Response;
}
try
{
SendClusterData();
}
catch(Exception e)
{
Console.WriteLine("Error sending cluster data");
Console.WriteLine(e);
_response.Close();
_response = null;
}
return _listener;
}
示例11: SendNotModified
public void SendNotModified(HttpListenerResponse response)
{
response.StatusCode = (int)HttpStatusCode.NotModified;
response.Close();
}
示例12: WriteAndFlushResponse
void WriteAndFlushResponse(HttpListenerResponse response, byte[] buffer)
{
response.ContentLength64 = buffer.Length;
using(Stream output = response.OutputStream)
{
output.Write(buffer, 0, buffer.Length);
}
response.Close();
}
示例13: FinalizeAcceptedResponse
private static void FinalizeAcceptedResponse(HttpListenerRequest request, HttpListenerResponse response, RevaleeTask task)
{
string remoteAddress = request.RemoteEndPoint.Address.ToString();
try
{
response.StatusCode = 200;
response.StatusDescription = "OK";
byte[] confirmation_number = Encoding.UTF8.GetBytes(task.CallbackId.ToString());
response.ContentLength64 = confirmation_number.LongLength;
response.OutputStream.Write(confirmation_number, 0, confirmation_number.Length);
}
finally
{
response.Close();
}
Supervisor.Telemetry.RecordAcceptedRequest();
Supervisor.LogEvent(string.Format("Request accepted for {0} @ {1:d} {1:t} from {2}. [{3}]", task.CallbackUrl.OriginalString, task.CallbackTime, remoteAddress, task.CallbackId), TraceEventType.Verbose);
}
示例14: FinalizeRejectedResponse
private static void FinalizeRejectedResponse(HttpListenerRequest request, HttpListenerResponse response, int statusCode, string statusDescription, Uri callbackUrl)
{
string remoteAddress = request.RemoteEndPoint.Address.ToString();
try
{
response.StatusCode = statusCode;
response.StatusDescription = statusDescription;
}
finally
{
response.Close();
}
Supervisor.Telemetry.RecordRejectedRequest();
if (callbackUrl == null)
{
Supervisor.LogEvent(string.Format("Request rejected from {0} due to: {1}.", remoteAddress, statusDescription), TraceEventType.Verbose);
}
else
{
Supervisor.LogEvent(string.Format("Request rejected for {0} from {1} due to: {2}.", callbackUrl.OriginalString, remoteAddress, statusDescription), TraceEventType.Verbose);
}
}
示例15: ProcessRequest
//.........这里部分代码省略.........
}
else
{
// In this case the message is chunk encoded, but m_httpRequest.InputStream actually does processing.
// So we we read until zero bytes are read.
bool readComplete = false;
int bufferSize = ReadPayload;
messageBuffer = new byte[bufferSize];
int offset = 0;
while (!readComplete)
{
while (offset < ReadPayload)
{
int noRead = m_httpRequest.InputStream.Read(messageBuffer, offset, messageLength - offset);
// If we read zero bytes - means this is end of message. This is how InputStream.Read for chunked encoded data.
if (noRead == 0)
{
readComplete = true;
break;
}
offset += noRead;
}
// If read was not complete - increase the buffer.
if (!readComplete)
{
bufferSize += ReadPayload;
byte[] newMessageBuf = new byte[bufferSize];
Array.Copy(messageBuffer, newMessageBuf, offset);
messageBuffer = newMessageBuf;
}
}
m_chunked = false;
}
// Process the soap request.
try
{
// Message byte buffer
byte[] soapRequest;
byte[] soapResponse = null;
// If this is an mtom message process attachments, else process the raw message
if (m_mtomHeader != null)
{
// Process the message
WsMessage response = ProcessRequestMessage(new WsMessage(messageBuffer, m_mtomHeader.boundary, m_mtomHeader.start));
if (response != null)
{
soapResponse = response.Message;
if (response.MessageType == WsMessageType.Mtom)
{
m_mtomHeader.boundary = response.BodyParts.Boundary;
m_mtomHeader.start = response.BodyParts.Start;
}
}
}
else
{
// Convert the message buffer to a byte array
soapRequest = messageBuffer;
// Performance debuging
DebugTiming timeDebuger = new DebugTiming();
timeDebuger.ResetStartTime("***Request Debug timer started");
// Process the message
WsMessage response = ProcessRequestMessage(new WsMessage(soapRequest));
if (response != null)
soapResponse = response.Message;
// Performance debuging
timeDebuger.PrintElapsedTime("***ProcessMessage Took");
}
// Display remote endpoint
System.Ext.Console.Write("Response To: " + m_httpRequest.RemoteEndPoint.ToString());
// Send the response
SendResponse(soapResponse);
}
catch (Exception e)
{
System.Ext.Console.Write(e.Message + " " + e.InnerException);
SendError(400, "Bad Request");
}
}
catch
{
System.Ext.Console.Write("Invalid request format. Request ignored.");
SendError(400, "Bad Request");
}
finally
{
m_httpResponse.Close();
}
}