本文整理汇总了C#中Bend.Util.HttpProcessor类的典型用法代码示例。如果您正苦于以下问题:C# HttpProcessor类的具体用法?C# HttpProcessor怎么用?C# HttpProcessor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpProcessor类属于Bend.Util命名空间,在下文中一共展示了HttpProcessor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: handleGETRequest
public override void handleGETRequest(HttpProcessor p)
{
Console.WriteLine("request: {0}", p.http_url);
p.writeSuccess();
//p.outputStream.WriteLine("<html><body><h1>test server</h1>");
//p.outputStream.WriteLine("Current Time: " + DateTime.Now.ToString());
//p.outputStream.WriteLine("url : {0}", p.http_url);
//p.outputStream.WriteLine("<form method=post action=/form>");
//p.outputStream.WriteLine("<input type=text name=foo value=foovalue>");
//p.outputStream.WriteLine("<input type=submit name=bar value=barvalue>");
//p.outputStream.WriteLine("</form>");
if (p.http_url.Contains("www"))
{
string appPath = Path.GetDirectoryName(Application.ExecutablePath);
string fileName = appPath + "/" + p.http_url.Substring(p.http_url.IndexOf("www"));
FileInfo fi = new FileInfo(fileName);
using (StreamReader sr = new StreamReader(fi.OpenRead()))
{
p.outputStream.Write(sr.ReadToEnd());
}
}
else
{
System.Web.Script.Serialization.JavaScriptSerializer j = new System.Web.Script.Serialization.JavaScriptSerializer();
p.outputStream.WriteLine(j.Serialize(Temps));
}
}
示例2: handleGETRequest
public override void handleGETRequest(HttpProcessor processor)
{
Console.WriteLine("--GET REQUEST BEGIN--");
Console.WriteLine("Request:\n\t" + processor.http_url);
Console.WriteLine("Parameter:");
Console.WriteLine("\nSearching Handler..");
foreach (ITaskReciverPlugin cmd in pluginLoader.LoadedPlugins)
{
if (processor.http_url.StartsWith(cmd.CommandTrigger))
{
Console.Write(" Found!");
List<Tuple<string, string>> param = new List<Tuple<string,string>>();
param = GetParams(processor.http_url, cmd.CommandTrigger);
param.ForEach(x => Console.WriteLine("\t" + x.Item1 + " = " + ((x.Item2 == "") ? "no value" : x.Item2)));
Console.WriteLine("Executing!");
Console.WriteLine("--GET REQUEST END--\n");
cmd.Execute(param);
processor.writeSuccess();
return;
}
}
processor.writeFailure();
Console.Write(" Non Found :(");
Console.WriteLine("--GET REQUEST END--\n");
}
示例3: CopyHeaders
private void CopyHeaders(HttpProcessor p, Recipe engine)
{
foreach (string key in p.HttpHeaders.Keys)
{
engine.SetMacro("q_" + key, p.HttpHeaders[key]);
}
int i = p.HttpUrl.IndexOf('?');
string path;
if (i == -1)
{
path = Unescape(p.HttpUrl);
}
else
{
path = Unescape(p.HttpUrl.Substring(0, i));
var query = p.HttpUrl.Substring(i + 1); // skip '?'
string[] pairs = query.Split('&');
foreach (string s in pairs)
{
string u = Unescape(s);
string[] t = u.Split('=');
string key = t[0];
string value = t.Length == 1 ? "" : t[1];
engine.SetMacro("q_" + key, value); // try to avoid clashing with existing macros by prefixing with q_
}
}
engine.SetMacro("query", path);
}
示例4: handlePOSTRequest
public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData)
{
Console.WriteLine("--POST REQUEST BEGIN--");
Console.WriteLine("Request:\n\t" + p.http_url);
Console.WriteLine("Answer:\n\tPost request not supported.");
Console.WriteLine("--POST REQUEST END--\n");
}
示例5: handlePOSTRequest
public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData)
{
Console.WriteLine("POST request: {0}", p.http_url);
string data = inputData.ReadToEnd();
Console.WriteLine(data);
try
{
var log = ToLog(data);
var ok_msg = "{\"code\":\"0\",\"msg\":\"ok\"}";
var msg_len = Encoding.UTF8.GetByteCount(ok_msg);
ProcessLog(log);
p.outputStream.Write("HTTP/1.0 200 OK\r\n");
p.outputStream.Write("Cache-Control: private, max-age=0\r\n");
p.outputStream.Write("Content-Type: text/html\r\n");
p.outputStream.Write(string.Format("Content-Length:{0}\r\n", msg_len));
p.outputStream.Write("Vary: Accept-Encoding\r\n");
p.outputStream.Write("Server: Microsoft-IIS/8.5\r\n\r\n");
p.outputStream.Write(ok_msg);
}
catch
{
p.outputStream.Write("HTTP/1.0 404 NOT FOUND\r\n");
p.outputStream.Write("Content-Length:0\r\n");
p.outputStream.Write("Content-Type: text/html\r\n");
p.outputStream.Write("Server: Microsoft-IIS/8.5\r\n\r\n");
}
}
示例6: WriteForm
private void WriteForm(HttpProcessor p)
{
string source = "PROGRAM test.";
try {
StreamReader stream = new StreamReader ("Test.abap");
source = stream.ReadToEnd ();
stream.Close ();
} catch (Exception e) {
}
p.writeSuccess ();
p.outputStream.WriteLine ("<html>");
p.outputStream.WriteLine ("<head>");
p.outputStream.WriteLine ("<script src=\"client.js\" type=\"text/javascript\"></script>");
p.outputStream.WriteLine ("</head>");
p.outputStream.WriteLine ("<body>");
p.outputStream.WriteLine ("<h1>openABAP</h1>");
p.outputStream.WriteLine ("<form name=screen method=get action=\"\">");
p.outputStream.WriteLine ("<textarea name=source cols=120 rows=30>");
p.outputStream.WriteLine (source);
p.outputStream.WriteLine ("</textarea>");
p.outputStream.WriteLine ("<input type=submit name=sy-ucomm value=OK onclick=\"return send();\">");
p.outputStream.WriteLine ("<br/><textarea name=result cols=120 rows=10 readonly></textarea>");
p.outputStream.WriteLine ("</form></body></html>");
}
示例7: handlePOSTRequest
public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData)
{
if (p.http_url.ToLower().Contains("setalarm"))
{
string args = inputData.ReadToEnd();
System.Web.Script.Serialization.JavaScriptSerializer j = new System.Web.Script.Serialization.JavaScriptSerializer();
SetAlarmArgs saa = j.Deserialize<SetAlarmArgs>(args);
if (NewAlarm != null)
{
if(saa.temp.Length == 0){
NewAlarm(saa.index, null);
}else{
double dbl = 0;
if(double.TryParse(saa.temp, out dbl)){
NewAlarm(saa.index, dbl);
}else{
NewAlarm(saa.index, null);
}
}
}
//NewAlarm(p.httpHeaders["temp"]);
p.outputStream.WriteLine( "ok");
}
else
{
Console.WriteLine("POST request: {0}", p.http_url);
string data = inputData.ReadToEnd();
p.outputStream.WriteLine("<html><body><h1>test server</h1>");
p.outputStream.WriteLine("<a href=/test>return</a><p>");
p.outputStream.WriteLine("postbody: <pre>{0}</pre>", data);
}
}
示例8: Deal
private void Deal(HttpProcessor p,string url, string data,bool isGet){
if(url==null){
return;
}
if(url=="/"||url.StartsWith("/room.php")||url.StartsWith("/room.json")){
//房间列表
p.writeSuccess();
p.outputStream.Write(GetContent(url, data));
}else if(url.StartsWith("/deck.php")){
//卡片列表
if(data.IndexOf("pwd=caicai")<0){
p.writeFailure();
return;
}
p.writeSuccess();
string[] args = data.Split('&');
foreach(string a in args){
if(a != null && a.StartsWith("name=")){
int i = a.IndexOf("=");
if(i>=0 && i< a.Length-1){
string name = a.Substring(i+1);
List<int> cards = GameManager.GameCards(name);
foreach(int id in cards){
p.outputStream.WriteLine(""+id);
}
}
}
}
}
else{
p.writeFailure();
}
}
示例9: HandlePOSTRequest
public override void HandlePOSTRequest(HttpProcessor p, StreamReader inputData)
{
//Console.WriteLine("POST request: {0}", p.HttpUrl);
var engine = (Recipe)_Engine.Clone();
CopyHeaders(p, engine);
engine.SetMacro(Response, inputData.ReadToEnd());
engine.Run(new LineReader(_Script, "POST"));
WriteResponse(p, engine);
}
示例10: HandleGETRequest
public override void HandleGETRequest(HttpProcessor p)
{
//Console.WriteLine("request: {0}", p.HttpUrl);
var engine = (Recipe)_Engine.Clone();
CopyHeaders(p, engine);
engine.SetMacro(Response, "");
engine.Run(new LineReader(_Script, "GET"));
WriteResponse(p, engine);
}
示例11: handlePOSTRequest
public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData)
{
Console.WriteLine("POST request: {0}", p.http_url);
string data = inputData.ReadToEnd();
p.outputStream.WriteLine("<html><body><h1>test server</h1>");
p.outputStream.WriteLine("<a href=/test>return</a><p>");
p.outputStream.WriteLine("postbody: <pre>{0}</pre>", data);
}
示例12: handleGETRequest
public override void handleGETRequest(HttpProcessor p)
{
string urlText = p.http_url;
int pos = urlText.IndexOf("&");
if (pos != -1)
{
urlText = urlText.Substring(0, pos);
}
if (urlText.EndsWith("/getSnapshot") == true)
{
p.writeSuccess("application/json");
p.outputStream.Write(_document.SnapshotText);
}
else if (urlText.Contains("/setSlide/") == true)
{
string txt = urlText.Substring(urlText.LastIndexOf('/') + 1);
int slide;
if (Int32.TryParse(txt, out slide) == true)
{
_document.SetCurrentSlide(slide);
}
p.writeSuccess("text/html");
p.outputStream.Write("OK");
}
else if (urlText.Contains("/startShow/") == true)
{
string txt = urlText.Substring(urlText.LastIndexOf('/') + 1);
int slide;
if (Int32.TryParse(txt, out slide) == true)
{
_document.StartShow(slide);
}
p.writeSuccess("text/html");
p.outputStream.Write("OK");
}
else if (urlText.Contains("/startShow") == true)
{
_document.StartShow(1);
p.writeSuccess("text/html");
p.outputStream.Write("OK");
}
else if (urlText.Contains("/nextAnimation") == true)
{
_document.NextAnimation();
p.writeSuccess("text/html");
p.outputStream.Write("OK");
}
}
示例13: listen
public void listen()
{
listener = new TcpListener(server, port);
listener.Start();
while (is_active)
{
TcpClient s = listener.AcceptTcpClient();
HttpProcessor processor = new HttpProcessor(s, this);
Thread thread = new Thread(new ThreadStart(processor.process));
thread.Start();
Thread.Sleep(1);
}
}
示例14: handlePOSTRequest
public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData)
{
Console.WriteLine("POST request: {0}", p.http_url);
var stopWatch = new Stopwatch();
stopWatch.Start();
string data = inputData.ReadToEnd();
var board = JsonConvert.DeserializeObject<DynaShipBoard>(data);
var response = new DynaShipAI(board).Process();
p.writeSuccess("application/json");
p.outputStream.Write(String.Format("{{\"x\": {0}, \"y\": {1}}}", response.X, response.Y));
stopWatch.Stop();
Console.WriteLine("Time taken: " + stopWatch.Elapsed);
}
示例15: handleGETRequest
public override void handleGETRequest(HttpProcessor p)
{
Console.WriteLine("request: {0}", p.http_url);
p.writeSuccess();
string callback = String.Empty;
this.setData(ParseParameters(p.http_url, out callback));
try
{
p.outputStream.WriteLine(callback + "(\"OK\")");
}
catch (Exception ex)
{
Console.WriteLine("Exception: {0}", ex.Message);
}
}