本文整理汇总了C#中HttpServerResponse类的典型用法代码示例。如果您正苦于以下问题:C# HttpServerResponse类的具体用法?C# HttpServerResponse怎么用?C# HttpServerResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpServerResponse类属于命名空间,在下文中一共展示了HttpServerResponse类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ParseToString
public string ParseToString(HttpServerResponse response)
{
if (response.Content == null)
return string.Empty;
return DEFAULT_CONTENT_ENCODING.GetString(response.Content);
}
开发者ID:anondesigns,项目名称:restup,代码行数:7,代码来源:ContentParser.cs
示例2: ParseToString
public string ParseToString(HttpServerResponse response)
{
var version = GetHttpVersion(response.HttpVersion);
var status = (int)response.ResponseStatus;
var statusText = HttpCodesTranslator.Default.GetHttpStatusCodeText(status);
return $"{version} {status} {statusText}\r\n";
}
开发者ID:anondesigns,项目名称:restup,代码行数:8,代码来源:StartLineParser.cs
示例3: ConvertToBytes
public byte[] ConvertToBytes(HttpServerResponse response)
{
var responseBytes = new List<byte>();
foreach (var pipelinePart in _pipeline)
{
responseBytes.AddRange(pipelinePart.ParseToBytes(response));
}
return responseBytes.ToArray();
}
开发者ID:anondesigns,项目名称:restup,代码行数:10,代码来源:HttpServerResponseParser.cs
示例4: ConvertToString
public string ConvertToString(HttpServerResponse response)
{
var responseBuilder = new StringBuilder();
foreach (var pipelinePart in _pipeline)
{
responseBuilder.Append(pipelinePart.ParseToString(response));
}
return responseBuilder.ToString();
}
开发者ID:anondesigns,项目名称:restup,代码行数:10,代码来源:HttpServerResponseParser.cs
示例5: ParseToString
public string ParseToString(HttpServerResponse response)
{
var headersTextBuilder = new StringBuilder();
foreach (var header in response.Headers)
{
headersTextBuilder.Append($"{header.Name}: {header.Value}\r\n");
}
headersTextBuilder.Append("\r\n");
return headersTextBuilder.ToString();
}
开发者ID:tomkuijsten,项目名称:restup,代码行数:12,代码来源:HeadersParser.cs
示例6: PendingEvent
public PendingEvent (double? Temp, double? TempDiff, double? Light, double? LightDiff, bool? Motion, int Timeout,
HttpServerResponse Response, string ContentType, ISensorDataExport ExportModule)
{
this.temp = Temp;
this.tempDiff = TempDiff;
this.light = Light;
this.lightDiff = LightDiff;
this.motion = Motion;
this.timeout = DateTime.Now.AddSeconds (Timeout);
this.response = Response;
this.contentType = ContentType;
this.exportModule = ExportModule;
}
开发者ID:mukira,项目名称:Learning-IoT-HTTP,代码行数:16,代码来源:PendingEvent.cs
示例7: HttpGetRoot
private static void HttpGetRoot (HttpServerResponse resp, HttpServerRequest req)
{
string SessionId = req.Header.GetCookie ("SessionId");
resp.ContentType = "text/html";
resp.Encoding = System.Text.Encoding.UTF8;
resp.ReturnCode = HttpStatusCode.Successful_OK;
if (CheckSession (SessionId))
{
resp.Write ("<html><head><title>Actuator</title></head><body><h1>Welcome to Actuator</h1><p>Below, choose what you want to do.</p><ul>");
resp.Write ("<li><a href='/credentials'>Update login credentials.</a></li>");
resp.Write ("<li><a href='/set'>Control Outputs</a></li>");
resp.Write ("<li>View Output States</li><ul>");
resp.Write ("<li><a href='/xml?Momentary=1'>View data as XML using REST</a></li>");
resp.Write ("<li><a href='/json?Momentary=1'>View data as JSON using REST</a></li>");
resp.Write ("<li><a href='/turtle?Momentary=1'>View data as TURTLE using REST</a></li>");
resp.Write ("<li><a href='/rdf?Momentary=1'>View data as RDF using REST</a></li></ul>");
resp.Write ("</ul></body></html>");
} else
OutputLoginForm (resp, string.Empty);
}
开发者ID:wrtcoder,项目名称:Learning-IoT-MQTT,代码行数:23,代码来源:Program.cs
示例8: HttpGetSensorData
private static void HttpGetSensorData (HttpServerResponse resp, string ContentType, ISensorDataExport ExportModule, ReadoutRequest Request)
{
networkLed.High ();
try
{
resp.ContentType = ContentType;
resp.Encoding = System.Text.Encoding.UTF8;
resp.Expires = DateTime.Now;
resp.ReturnCode = HttpStatusCode.Successful_OK;
ExportSensorData (ExportModule, Request);
} finally
{
networkLed.Low ();
}
}
开发者ID:mukira,项目名称:Learning-IoT-HTTP,代码行数:17,代码来源:Program.cs
示例9: HttpGetSensorData
private static void HttpGetSensorData (HttpServerResponse resp, HttpServerRequest req, string ContentType, ISensorDataExport ExportModule)
{
ReadoutRequest Request = new ReadoutRequest (req);
HttpGetSensorData (resp, ContentType, ExportModule, Request);
}
开发者ID:wrtcoder,项目名称:Learning-IoT-MQTT,代码行数:5,代码来源:Program.cs
示例10: HttpGetTurtle
private static void HttpGetTurtle (HttpServerResponse resp, HttpServerRequest req)
{
HttpGetSensorData (resp, req, "text/turtle", new SensorDataTurtleExport (resp.TextWriter, req));
}
开发者ID:wrtcoder,项目名称:Learning-IoT-MQTT,代码行数:4,代码来源:Program.cs
示例11: HttpGetXml
private static void HttpGetXml (HttpServerResponse resp, HttpServerRequest req)
{
HttpGetSensorData (resp, req, "text/xml", new SensorDataXmlExport (resp.TextWriter));
}
开发者ID:wrtcoder,项目名称:Learning-IoT-MQTT,代码行数:4,代码来源:Program.cs
示例12: HttpGetSet
private static void HttpGetSet (HttpServerResponse resp, HttpServerRequest req)
{
string s;
int i;
bool b;
foreach (KeyValuePair<string,string> Query in req.Query)
{
if (!XmlUtilities.TryParseBoolean (Query.Value, out b))
continue;
s = Query.Key.ToLower ();
if (s == "alarm")
{
if (b)
{
AlarmOn ();
state.Alarm = true;
} else
{
AlarmOff ();
state.Alarm = false;
}
} else if (s.StartsWith ("do") && int.TryParse (s.Substring (2), out i) && i >= 1 && i <= 8)
{
digitalOutputs [i - 1].Value = b;
state.SetDO (i, b);
}
}
state.UpdateIfModified ();
resp.ContentType = "text/html";
resp.Encoding = System.Text.Encoding.UTF8;
resp.ReturnCode = HttpStatusCode.Successful_OK;
resp.Write ("<html><head><title>Actuator</title></head><body><h1>Control Actuator Outputs</h1>");
resp.Write ("<form method='POST' action='/set' target='_self'><p>");
for (i = 0; i < 8; i++)
{
resp.Write ("<input type='checkbox' name='do");
resp.Write ((i + 1).ToString ());
resp.Write ("'");
if (digitalOutputs [i].Value)
resp.Write (" checked='checked'");
resp.Write ("/> Digital Output ");
resp.Write ((i + 1).ToString ());
resp.Write ("<br/>");
}
resp.Write ("<input type='checkbox' name='alarm'");
if (alarmThread != null)
resp.Write (" checked='checked'");
resp.Write ("/> Alarm</p>");
resp.Write ("<p><input type='submit' value='Set'/></p></form></body></html>");
}
开发者ID:wrtcoder,项目名称:Learning-IoT-MQTT,代码行数:57,代码来源:Program.cs
示例13: OutputCredentialsForm
private static void OutputCredentialsForm (HttpServerResponse resp, string Message)
{
resp.Write ("<html><head><title>Actuator</title></head><body><form method='POST' action='/credentials' target='_self' autocomplete='true'>");
resp.Write (Message);
resp.Write ("<h1>Update Login Credentials</h1><p><label for='UserName'>User Name:</label><br/><input type='text' name='UserName'/></p>");
resp.Write ("<p><label for='Password'>Password:</label><br/><input type='password' name='Password'/></p>");
resp.Write ("<p><label for='NewUserName'>New User Name:</label><br/><input type='text' name='NewUserName'/></p>");
resp.Write ("<p><label for='NewPassword1'>New Password:</label><br/><input type='password' name='NewPassword1'/></p>");
resp.Write ("<p><label for='NewPassword2'>New Password again:</label><br/><input type='password' name='NewPassword2'/></p>");
resp.Write ("<p><input type='submit' value='Update'/></p></form></body></html>");
}
开发者ID:wrtcoder,项目名称:Learning-IoT-MQTT,代码行数:11,代码来源:Program.cs
示例14: HttpPostRoot
private static void HttpPostRoot (HttpServerResponse resp, HttpServerRequest req)
{
FormParameters Parameters = req.Data as FormParameters;
if (Parameters == null)
throw new HttpException (HttpStatusCode.ClientError_BadRequest);
string UserName = Parameters ["UserName"];
string Password = Parameters ["Password"];
string Hash;
object AuthorizationObject;
GetDigestUserPasswordHash (UserName, out Hash, out AuthorizationObject);
if (AuthorizationObject == null || Hash != CalcHash (UserName, Password))
{
resp.ContentType = "text/html";
resp.Encoding = System.Text.Encoding.UTF8;
resp.ReturnCode = HttpStatusCode.Successful_OK;
Log.Warning ("Invalid login attempt.", EventLevel.Minor, UserName, req.ClientAddress);
OutputLoginForm (resp, "<p>The login was incorrect. Either the user name or the password was incorrect. Please try again.</p>");
} else
{
Log.Information ("User logged in.", EventLevel.Minor, UserName, req.ClientAddress);
string SessionId = CreateSessionId (UserName);
resp.SetCookie ("SessionId", SessionId, "/");
resp.ReturnCode = HttpStatusCode.Redirection_SeeOther;
resp.AddHeader ("Location", "/");
resp.SendResponse ();
// PRG pattern, to avoid problems with post back warnings in the browser: http://en.wikipedia.org/wiki/Post/Redirect/Get
}
}
开发者ID:wrtcoder,项目名称:Learning-IoT-MQTT,代码行数:33,代码来源:Program.cs
示例15: HttpGetRoot
private static void HttpGetRoot (HttpServerResponse resp, HttpServerRequest req)
{
networkLed.High ();
try
{
resp.ContentType = "text/html";
resp.Encoding = System.Text.Encoding.UTF8;
resp.ReturnCode = HttpStatusCode.Successful_OK;
resp.Write ("<html><head><title>Sensor</title></head><body><h1>Welcome to Sensor</h1><p>Below, choose what you want to do.</p><ul>");
resp.Write ("<li>View Data</li><ul>");
resp.Write ("<li><a href='/xml?Momentary=1'>View data as XML using REST</a></li>");
resp.Write ("<li><a href='/json?Momentary=1'>View data as JSON using REST</a></li>");
resp.Write ("<li><a href='/turtle?Momentary=1'>View data as TURTLE using REST</a></li>");
resp.Write ("<li><a href='/rdf?Momentary=1'>View data as RDF using REST</a></li>");
resp.Write ("<li><a href='/html'>Data in a HTML page with graphs</a></li></ul>");
resp.Write ("</body></html>");
} finally
{
networkLed.Low ();
}
}
开发者ID:mukira,项目名称:Learning-IoT-HTTP,代码行数:22,代码来源:Program.cs
示例16: ParseToBytes
public byte[] ParseToBytes(HttpServerResponse response)
{
return response.Content ?? new byte[0];
}
开发者ID:anondesigns,项目名称:restup,代码行数:4,代码来源:ContentParser.cs
示例17: HttpGetImgUnprotected
private static void HttpGetImgUnprotected (HttpServerResponse resp, HttpServerRequest req)
{
HttpGetImg (resp, req, false);
}
开发者ID:wrtcoder,项目名称:Learning-IoT-MQTT,代码行数:4,代码来源:Program.cs
示例18: HttpGetImg
private static void HttpGetImg (HttpServerResponse resp, HttpServerRequest req, bool Protected)
{
networkLed.High ();
try
{
if (Protected)
{
string SessionId = req.Header.GetCookie ("SessionId");
if (!CheckSession (SessionId))
throw new HttpException (HttpStatusCode.ClientError_Forbidden);
}
LinkSpriteJpegColorCamera.ImageSize Resolution;
string Encoding;
byte Compression;
ushort Size;
byte[] Data;
GetImageProperties (req, out Encoding, out Compression, out Resolution);
lock (cameraLed)
{
try
{
cameraLed.High ();
if (Resolution != currentResolution)
{
try
{
camera.SetImageSize (Resolution);
currentResolution = Resolution;
camera.Reset ();
} catch (Exception)
{
camera.Dispose ();
camera = new LinkSpriteJpegColorCamera (LinkSpriteJpegColorCamera.BaudRate.Baud__38400);
camera.SetBaudRate (LinkSpriteJpegColorCamera.BaudRate.Baud_115200);
camera.Dispose ();
camera = new LinkSpriteJpegColorCamera (LinkSpriteJpegColorCamera.BaudRate.Baud_115200);
}
}
if (Compression != currentCompressionRatio)
{
camera.SetCompressionRatio (Compression);
currentCompressionRatio = Compression;
}
camera.TakePicture ();
Size = camera.GetJpegFileSize ();
Data = camera.ReadJpegData (Size);
errorLed.Low ();
} catch (Exception ex)
{
errorLed.High ();
Log.Exception (ex);
throw new HttpException (HttpStatusCode.ServerError_ServiceUnavailable);
} finally
{
cameraLed.Low ();
camera.StopTakingPictures ();
}
}
resp.ContentType = Encoding;
resp.Expires = DateTime.Now;
resp.ReturnCode = HttpStatusCode.Successful_OK;
if (Encoding != "imgage/jpeg")
{
MemoryStream ms = new MemoryStream (Data);
Bitmap Bmp = new Bitmap (ms);
Data = MimeUtilities.EncodeSpecificType (Bmp, Encoding);
}
resp.WriteBinary (Data);
} finally
{
networkLed.Low ();
}
}
开发者ID:wrtcoder,项目名称:Learning-IoT-MQTT,代码行数:85,代码来源:Program.cs
示例19: HttpGetCredentials
private static void HttpGetCredentials (HttpServerResponse resp, HttpServerRequest req)
{
string SessionId = req.Header.GetCookie ("SessionId");
if (!CheckSession (SessionId))
throw new HttpTemporaryRedirectException ("/");
resp.ContentType = "text/html";
resp.Encoding = System.Text.Encoding.UTF8;
resp.ReturnCode = HttpStatusCode.Successful_OK;
OutputCredentialsForm (resp, string.Empty);
}
开发者ID:wrtcoder,项目名称:Learning-IoT-MQTT,代码行数:12,代码来源:Program.cs
示例20: OnHttpServerRequest
private void OnHttpServerRequest(HttpServerRequest httpRequest, HttpServerResponse httpResponse)
{
UrlData urlData = Url.Parse(httpRequest.Url, /* parseQueryString */ true);
ServerRoute route = _router.Match(urlData.PathName);
Action<Exception> errorHandler = delegate(Exception e) {
httpResponse.WriteHead(HttpStatusCode.InternalServerError, e.Message);
httpResponse.End();
Runtime.TraceInfo("500 : %s %s", httpRequest.Method, httpRequest.Url);
return;
};
ServerRequest request = new ServerRequest(httpRequest, urlData, route);
Task<ServerResponse> responseTask = null;
try {
responseTask = _modules[0].ProcessRequest(request);
}
catch (Exception e) {
errorHandler(e);
return;
}
responseTask.Done(delegate(ServerResponse response) {
response.Write(httpResponse);
Runtime.TraceInfo("%d : %s %s", response.StatusCode, httpRequest.Method, httpRequest.Url);
})
.Fail(errorHandler);
}
开发者ID:nikhilk,项目名称:simplecloud,代码行数:31,代码来源:ServerRuntime.cs
注:本文中的HttpServerResponse类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论