本文整理汇总了C#中System.Net.HttpListenerRequest类的典型用法代码示例。如果您正苦于以下问题:C# HttpListenerRequest类的具体用法?C# HttpListenerRequest怎么用?C# HttpListenerRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpListenerRequest类属于System.Net命名空间,在下文中一共展示了HttpListenerRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Handle
public override IResponseFormatter Handle(HttpListenerRequest request)
{
var transportManager = Singleton<TransportManager>.instance;
if (transportManager == null)
return JsonResponse(new Dictionary<string, List<PublicTransportLine>>());
var lines = transportManager.m_lines.m_buffer.ToList();
if (lines == null)
return JsonResponse(new Dictionary<string, List<PublicTransportLine>>());
var busLines = lines.Where(x => x.Info.m_class.m_subService == ItemClass.SubService.PublicTransportBus);
var metroLines = lines.Where(x => x.Info.m_class.m_subService == ItemClass.SubService.PublicTransportMetro);
var trainLines = lines.Where(x => x.Info.m_class.m_subService == ItemClass.SubService.PublicTransportTrain);
var shipLines = lines.Where(x => x.Info.m_class.m_subService == ItemClass.SubService.PublicTransportShip);
var planeLines = lines.Where(x => x.Info.m_class.m_subService == ItemClass.SubService.PublicTransportPlane);
Dictionary<string, List<PublicTransportLine>> allTransportLines = new Dictionary<string, List<PublicTransportLine>>()
{
{"BusLines", MakeLinesModels(busLines)},
{"MetroLines", MakeLinesModels(metroLines)},
{"TrainLines", MakeLinesModels(trainLines)},
{"ShipLines", MakeLinesModels(shipLines)},
{"PlaneLines", MakeLinesModels(planeLines)},
};
return JsonResponse(allTransportLines);
}
示例2: RestRequest
public RestRequest(HttpListenerRequest request)
{
this.HttpMethod = request.HttpMethod;
this.Url = request.Url;
this.RESTModuleName = request.Url.Segments[1].Replace("/", "");
this.RESTMethodName = request.Url.Segments[2].Replace("/", "");
this.RESTMethodParameters = request.QueryString;
this.Cookies = request.Cookies;
if (request.HasEntityBody)
{
Encoding encoding = request.ContentEncoding;
using (var bodyStream = request.InputStream)
using (var streamReader = new StreamReader(bodyStream, encoding))
{
if (request.ContentType != null)
{
this.ContentType = request.ContentType;
}
this.ContentLength = request.ContentLength64;
this.Body = streamReader.ReadToEnd();
}
if (this.HttpMethod == "POST" && this.ContentType == "application/x-www-form-urlencoded")
{
this.RESTMethodParameters = ParseQueryString(System.Uri.UnescapeDataString(this.Body));
}
}
}
示例3: WebserviceRequest
public WebserviceRequest(string url, string rawdata, HttpListenerRequest request)
{
URL = url;
RawData = rawdata;
RawRequest = request;
ParseData();
}
示例4: Handle
public override IResponseFormatter Handle(HttpListenerRequest request)
{
// TODO: Customize request handling.
var messages = _chirpRetriever.Messages;
return JsonResponse(messages);
}
示例5: Handle
public override IResponseFormatter Handle(HttpListenerRequest request)
{
var buildingManager = Singleton<BuildingManager>.instance;
if (request.Url.AbsolutePath.StartsWith("/Building/List"))
{
List<ushort> buildingIDs = new List<ushort>();
var len = buildingManager.m_buildings.m_buffer.Length;
for (ushort i = 0; i < len; i++)
{
if (buildingManager.m_buildings.m_buffer[i].m_flags == Building.Flags.None) { continue; }
buildingIDs.Add(i);
}
return JsonResponse(buildingIDs);
}
foreach (var building in buildingManager.m_buildings.m_buffer)
{
if (building.m_flags == Building.Flags.None) { continue; }
// TODO: Something with Buildings.
}
return JsonResponse("");
}
示例6: 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");
}
}
示例7: HttpRequest
/// <summary>
/// Creates a new instance of HttpRequest
/// </summary>
/// <param name="Client">The HttpClient creating this response</param>
public HttpRequest(HttpListenerRequest Request, HttpClient Client)
{
// Create a better QueryString object
this.QueryString = Request.QueryString.Cast<string>().ToDictionary(p => p, p => Request.QueryString[p]);
this.Request = Request;
this.Client = Client;
}
示例8: HttpListenerRequestWrapper
public HttpListenerRequestWrapper(HttpListenerRequest httpListenerRequest)
{
_httpListenerRequest = httpListenerRequest;
_qs = new NameValueCollection(httpListenerRequest.QueryString);
_headers = new NameValueCollection(httpListenerRequest.Headers);
_cookies = new CookieCollectionWrapper(_httpListenerRequest.Cookies);
}
示例9: 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();
}
示例10: Find
public RouteHandler Find(HttpListenerRequest request, out UriTemplateMatch templateMatch)
{
var reqId = request.HttpMethod + ":" + request.Url.LocalPath;
KeyValuePair<RouteHandler, Uri> rh;
if (Cache.TryGetValue(reqId, out rh))
{
templateMatch = rh.Key.Template.Match(rh.Value, request.Url);
return rh.Key;
}
templateMatch = null;
List<RouteHandler> handlers;
if (!MethodRoutes.TryGetValue(request.HttpMethod, out handlers))
return null;
var reqUrl = request.Url;
var url = reqUrl.ToString();
var baseAddr = new Uri(url.Substring(0, url.Length - request.RawUrl.Length));
foreach (var h in handlers)
{
var match = h.Template.Match(baseAddr, reqUrl);
if (match != null)
{
templateMatch = match;
Cache.TryAdd(reqId, new KeyValuePair<RouteHandler, Uri>(h, baseAddr));
return h;
}
}
return null;
}
示例11: 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 { }
}
}
示例12: Handle
/// <summary>
/// 处理程序
/// </summary>
/// <param name="request">请求上下文</param>
public string Handle(HttpListenerRequest requestContext)
{
var command = requestContext.QueryString["command"];
//byte[] fileBuffer = new byte[1024 * 32];
//using (MemoryStream ms = new MemoryStream())
//{
// while (true)
// {
// int read = requestContext.InputStream.Read(fileBuffer, 0, fileBuffer.Length);
// if (read <= 0)
// {
// FileStream fs = new FileStream("C:\\111.xlsx", FileMode.OpenOrCreate);
// byte[] buff = ms.ToArray();
// fs.Write(buff, 0, buff.Length);
// fs.Close();
// break;
// }
// ms.Write(fileBuffer, 0, read);
// }
//}
return "200";
}
示例13: HandleCreateAccount
private static string HandleCreateAccount(HttpServer server, HttpListenerRequest request, Dictionary<string, string> parameters)
{
if (!parameters.ContainsKey("username")) throw new Exception("Missing username.");
if (!parameters.ContainsKey("password")) throw new Exception("Missing password.");
string username = parameters["username"];
string password = parameters["password"];
if (Databases.AccountTable.Count(a => a.Username.ToLower() == username.ToLower()) > 0) return JsonEncode("Username already in use!");
System.Text.RegularExpressions.Regex invalidCharacterRegex = new System.Text.RegularExpressions.Regex("[^a-zA-Z0-9]");
if (invalidCharacterRegex.IsMatch(username)) return JsonEncode("Invalid characters detected in username!");
Random getrandom = new Random();
String token = getrandom.Next(10000000, 99999999).ToString();
AccountEntry entry = new AccountEntry();
entry.Index = Databases.AccountTable.GenerateIndex();
entry.Username = username;
entry.Password = password;
entry.Verifier = "";
entry.Salt = "";
entry.RTW_Points = 0;
entry.IsAdmin = 0;
entry.IsBanned = 0;
entry.InUse = 0;
entry.extrn_login = 0;
entry.CanHostDistrict = 1;
entry.Token = token;
Databases.AccountTable.Add(entry);
Log.Succes("HTTP", "Successfully created account '" + username + "'");
return JsonEncode("Account created!\n\nYour token is: " + token + ".\nCopy and paste given token in \"_rtoken.id\" file and put it in the same folder where your \"APB.exe\" is located.");
}
示例14: HttpRequest
public HttpRequest(HttpListenerRequest listenerRequest)
{
_request = listenerRequest;
_formData = new FormData(listenerRequest);
LoadFormData();
}
示例15: HttpListenerRequestAdapter
public HttpListenerRequestAdapter(HttpListenerRequest request)
{
this.request = request;
this.queryString = System.Web.HttpUtility.ParseQueryString(Uri.UnescapeDataString(request.Url.Query));
Url = this.request.Url;
RawUrl = this.request.RawUrl;
}