本文整理汇总了C#中HttpServer.RequestEventArgs类的典型用法代码示例。如果您正苦于以下问题:C# RequestEventArgs类的具体用法?C# RequestEventArgs怎么用?C# RequestEventArgs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RequestEventArgs类属于HttpServer命名空间,在下文中一共展示了RequestEventArgs类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnRequestDesbloqueio
public void OnRequestDesbloqueio(object sender, RequestEventArgs e)
{
e.Response.Connection.Type = ConnectionType.Close;
e.Response.ContentType.Value = "text/xml";
if (unlockSent == 0)
{
unlockSent++;
string opcionais = "";
int numparams = 1;
if (checkBox1.Checked)
{
opcionais += "<ParameterValueStruct><Name>InternetGatewayDevice.Services.X_Pace_Com.Services.SSH.Enable</Name><Value xsi:type=\"xsd:unsignedInt\">1</Value></ParameterValueStruct>";
numparams++;
}
timer1.Stop();
AppendTextBox("\r\nModem conectado, enviando configuração.\r\n");
byte[] buffer = Encoding.Default.GetBytes("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<soap-env:Envelope xmlns:soap-enc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:soap-env=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:cwmp=\"urn:dslforum-org:cwmp-1-0\"><soap-env:Header><cwmp:ID soap-env:mustUnderstand=\"1\">55882f2177ab936c3f062f8f</cwmp:ID></soap-env:Header><soap-env:Body><cwmp:SetParameterValues><ParameterList soap-enc:arrayType=\"cwmp:ParameterValueStruct["+numparams+"]\"><ParameterValueStruct><Name>InternetGatewayDevice.Services.X_Pace_Com.Services.GvtConfig.AccessClass</Name><Value xsi:type=\"xsd:unsignedInt\">4</Value></ParameterValueStruct>"+opcionais+"</ParameterList><ParameterKey/></cwmp:SetParameterValues></soap-env:Body></soap-env:Envelope>");
e.Response.Body.Write(buffer, 0, buffer.Length);
AppendTextBox("Finalizado.\r\n");
}
else if (unlockSent < 2)
{
unlockSent++;
byte[] buffer = Encoding.Default.GetBytes("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<soap-env:Envelope xmlns:soap-enc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:soap-env=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:cwmp=\"urn:dslforum-org:cwmp-1-0\"><soap-env:Header><cwmp:ID soap-env:mustUnderstand=\"1\">null</cwmp:ID></soap-env:Header><soap-env:Body><cwmp:InformResponse><MaxEnvelopes>1</MaxEnvelopes></cwmp:InformResponse></soap-env:Body></soap-env:Envelope>");
e.Response.Body.Write(buffer, 0, buffer.Length);
}
else
{
unlockSent = 1;
e.Response.Status = HttpStatusCode.NoContent;
}
}
示例2: OnRequest
private static void OnRequest(object sender, RequestEventArgs e)
{
if (e.Request.Method == Method.Post)
{
}
}
示例3: listener_RequestReceived
static void listener_RequestReceived(object sender, RequestEventArgs e)
{
var virtualPath = e.Request.Uri.AbsolutePath.TrimStart('/').Replace("/","\\");
var stream = ProcessPath(virtualPath, "index.html");
if (stream != null)
CopyStream(stream, e.Response.Body);
}
示例4: Handle
public bool Handle(RequestEventArgs e)
{
NetworkRequest req = Multiplexor.Decode(e.Request);
logger.Trace("Client rx: {0} p: {1} source: {2} overlord: {3}", req.Verb, req.Param, req.SourceID,
req.OverlordID);
switch (req.Verb)
{
case "BROWSE":
return HandleBrowse(e, req);
case "UPDATE":
return HandleUpdate(e, req);
case "INFO":
return HandleInfo(e);
case "NOOP":
return HandleNOOP(e, req);
case "GET":
return HandleGet(e, req);
case "DISCONNECT":
return HandleDisconnect(e);
case "CHAT":
return HandleChat(e, req);
case "COMPARE":
return HandleCompare(e, req);
case "SEARCH":
return HandleSearch(e, req);
case "CONVERSTATION":
return HandleConversation(e, req);
case "ADDDOWNLOAD":
return HandleAddDownload(e, req);
}
return false;
}
示例5: OnSecureRequest
private void OnSecureRequest(object source, RequestEventArgs args)
{
IHttpClientContext context = (IHttpClientContext)source;
IHttpRequest request = args.Request;
// Here we create a response object, instead of using the client directly.
// we can use methods like Redirect etc with it,
// and we dont need to keep track of any headers etc.
IHttpResponse response = request.CreateResponse(context);
byte[] body = Encoding.UTF8.GetBytes("Hello secure you!");
response.Body.Write(body, 0, body.Length);
response.Send();
}
示例6: OnRequest
private void OnRequest(object source, RequestEventArgs args)
{
IHttpClientContext context = (IHttpClientContext)source;
IHttpRequest request = args.Request;
// Respond is a small convenience function that let's you send one string to the browser.
// you can also use the Send, SendHeader and SendBody methods to have total control.
if (request.Uri.AbsolutePath == "/hello")
context.Respond("Hello to you too!");
else if (request.UriParts.Length == 1 && request.UriParts[0] == "goodbye")
{
IHttpResponse response = request.CreateResponse(context);
StreamWriter writer = new StreamWriter(response.Body);
writer.WriteLine("Goodbye to you too!");
writer.Flush();
response.Send();
}
}
示例7: OnRequest
private static void OnRequest(object sender, RequestEventArgs e)
{
#if DEBUG
lock (_lockObj)
{
Console.WriteLine(("Begin Request").Wrap("-", Console.WindowWidth));
Console.WriteLine(string.Format("Request from {0}", e.Context.RemoteEndPoint.Address.ToString()));
if (e.Response.Status == HttpStatusCode.OK)
{
Console.WriteLine(string.Format("The request for {0} was successful", e.Request.Uri.ToString()));
}
else
{
Console.WriteLine(string.Format("The request for {0} failed", e.Request.Uri.ToString()));
}
Console.WriteLine(("End Request").Wrap("-", Console.WindowWidth));
}
#endif
}
示例8: OnRequest
private void OnRequest(object sender, RequestEventArgs e)
{
String url = "https://v.whatsapp.net" + e.Request.Uri.PathAndQuery;
HttpWebRequest request = HttpWebRequest.Create(url) as HttpWebRequest;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
e.Response.ContentType.Value = response.ContentType;
e.Response.ContentLength.Value = response.ContentLength;
Stream responseStream = response.GetResponseStream();
StreamReader responseReader = new StreamReader(responseStream);
String data = responseReader.ReadToEnd();
byte[] data2 = Encoding.Default.GetBytes(data);
e.Response.Body.Write(data2, 0, data2.Length);
this.AddListItem("REQUEST: " + e.Request.Uri.AbsoluteUri);
this.AddListItem("RESPONSE: " + data);
this.AddListItem(" ");
}
示例9: ExecuteCommand
protected override object ExecuteCommand(RestCommand cmd, RestVerbs verbs, IParameterCollection parms, RequestEventArgs e)
{
if (cmd.RequiresToken)
{
var strtoken = parms["token"];
if (strtoken == null)
return new Dictionary<string, string>
{{"status", "401"}, {"error", "Not authorized. The specified API endpoint requires a token."}};
object token;
if (!Tokens.TryGetValue(strtoken, out token))
return new Dictionary<string, string>
{
{"status", "403"},
{
"error",
"Not authorized. The specified API endpoint requires a token, but the provided token was not valid."
}
};
}
return base.ExecuteCommand(cmd, verbs, parms, e);
}
示例10: listener_RequestReceived
private void listener_RequestReceived(object sender, RequestEventArgs e)
{
e.IsHandled = true;
e.Response.Reason = string.Empty;
string userAgent = string.Empty;
IHeader uahead =
e.Request.Headers.Where(h => string.Equals("User-Agent", h.Name, StringComparison.OrdinalIgnoreCase)).
FirstOrDefault();
if (null != uahead)
userAgent = uahead.HeaderValue;
//Send to the correct handler
if (userAgent.StartsWith("FAP"))
{
if (OnRequest(RequestType.FAP, e))
return;
}
if (OnRequest(RequestType.HTTP, e))
return;
e.Response.Reason = "Handler error";
e.Response.Status = HttpStatusCode.InternalServerError;
var generator = new ResponseWriter();
generator.SendHeaders(e.Context, e.Response);
}
示例11: OnRequestReceived
private void OnRequestReceived(object sender, RequestEventArgs e)
{
RequestReceived(sender, e);
}
示例12: HandleSearch
private bool HandleSearch(RequestEventArgs e, NetworkRequest req)
{
//We dont do this on a server..
var verb = new SearchVerb(shareInfoService);
NetworkRequest result = verb.ProcessRequest(req);
byte[] data = Encoding.UTF8.GetBytes(result.Data);
var generator = new ResponseWriter();
e.Response.ContentLength.Value = data.Length;
generator.SendHeaders(e.Context, e.Response);
e.Context.Stream.Write(data, 0, data.Length);
e.Context.Stream.Flush();
data = null;
return true;
}
示例13: OnHttpListenerRequestReceived
private void OnHttpListenerRequestReceived(object sender, RequestEventArgs e)
{
IHttpClientContext context = (IHttpClientContext)sender;
lock (_serverData.SyncObj)
if (!_serverData.IsActive)
return;
HandleHTTPRequest_NoLock(context, e.Request);
}
示例14: OnRequest
protected virtual void OnRequest(object sender, RequestEventArgs e)
{
var obj = ProcessRequest(sender, e);
if (obj == null)
throw new NullReferenceException("obj");
var str = JsonConvert.SerializeObject(obj, Formatting.Indented);
e.Response.Connection.Type = ConnectionType.Close;
e.Response.Body.Write(Encoding.ASCII.GetBytes(str), 0, str.Length);
e.Response.Status = HttpStatusCode.OK;
return;
}
示例15: ProcessRequest
protected virtual object ProcessRequest(object sender, RequestEventArgs e)
{
var uri = e.Request.Uri.AbsolutePath;
uri = uri.TrimEnd('/');
foreach (var com in commands)
{
var verbs = new RestVerbs();
if (com.HasVerbs)
{
var match = Regex.Match(uri, com.UriVerbMatch);
if (!match.Success)
continue;
if ((match.Groups.Count - 1) != com.UriVerbs.Length)
continue;
for (int i = 0; i < com.UriVerbs.Length; i++)
verbs.Add(com.UriVerbs[i], match.Groups[i + 1].Value);
}
else if (com.UriTemplate.ToLower() != uri.ToLower())
{
continue;
}
var obj = ExecuteCommand(com, verbs, e.Request.Parameters);
if (obj != null)
return obj;
}
return new Dictionary<string, string> { { "status", "404" }, { "error", "Specified API endpoint doesn't exist. Refer to the documentation for a list of valid endpoints." } };
}