• winform监听网页请求


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml;
    using System.IO;
    using System.Net;
    using System.Windows.Forms;
    using System.Xml.Linq;

    namespace WindowsFormService
    {
    public class LFHttpListener
    {
    public void listener()
    {

    // System.Console.WriteLine(System.Net.HttpListener.IsSupported ? "可用于本系统" : "不可用于本系统");

    if (!HttpListener.IsSupported)
    {
    MessageBox.Show("本系统只支持xp sp2/win2003");
    return;
    }
    System.Net.HttpListener httplistener = new System.Net.HttpListener();
    string s = string.Format(XMLTools.getXmlValue("LCListenerAddress","Address"));
    httplistener.Prefixes.Add(s);
    httplistener.Start();
    while (true)
    {
    System.IAsyncResult ia2 = httplistener.BeginGetContext(
    delegate(System.IAsyncResult ia)
    {
    acceptAndResponse(ia);
    },
    httplistener
    );


    System.Threading.Thread.Sleep(1000);
    }
    }

    private void acceptAndResponse(IAsyncResult ia)
    {

    //接收
    var request = (HttpListener)ia.AsyncState;
    var hlc = request.EndGetContext(ia);
    XDocument xdoc = new XDocument();
    StreamReader inputStream = new StreamReader(hlc.Request.InputStream);
    string xml = inputStream.ReadToEnd();
    XmlDocument doc = new XmlDocument();
    doc.LoadXml(xml);
    //XmlDocument转换成XDocument
    xdoc = doc.ToXDocument();
    //把接收到的XML传递处理,并返回响应XML
    var acceptAndSendXml = new AcceptAndSendXml();
    var reXml = acceptAndSendXml.AcceptXml(xdoc);

    //XDocument转换成XmlDocument
    // XmlDoc.LoadXml(XDoc.Document.ToString());

    //响应XML
    hlc.Response.ContentType = "text/xml";
    System.IO.StreamWriter sw = new System.IO.StreamWriter(
    hlc.Response.OutputStream,
    System.Text.Encoding.Default
    );
    sw.Write(reXml);
    sw.Flush();
    sw.Close();
    }


    }
    }

  • 相关阅读:
    覆盖率测试工具gcov的前端工具_LCOV
    LTE切换与TAU问题
    LTE 切换过程中的数据切换
    TCP数据流稳定性--TCP分片,重组及乱序
    【Android
    【Android
    【Android
    【RN
    【RN
    【RN
  • 原文地址:https://www.cnblogs.com/cotty/p/2321866.html
Copyright © 2020-2023  润新知