繁体   English   中英

基于xampp / wamp的Apache服务器自定义回复

[英]xampp/wamp based Apache server custom reply

在连接到特定端口时,如何在基于xampp / wamp的Apache服务器上基于自定义请求发送自定义响应?

我正在尝试答复Flash应用程序请求的\\ 0,以允许跨域http GET请求。

闪存策略请求默认情况下是向端口843发出的,我希望保持这种状态。

端口应获得\\ 0(以空字符结尾,\\ 0仅作为参考),并以类似以下内容的方式答复:

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd">
    <cross-domain-policy>
        <site-control permitted-cross-domain-policies="master-only"/>
        <allow-http-request-headers-from domain="*" headers="*" secure="true" />
      <allow-access-from domain="*" to-ports="*" />
    </cross-domain-policy>

据我所知,该请求应以纯文本形式返回,尽管也可能需要Content-type。

我尝试使用以下命令: http : //socketpolicyserver.com/ ,尽管它侦听端口并接受连接,但它不会根据请求以指定的xml进行回复。

任何获得适当回复的方法/方式都将受到赞赏,

带着敬意,

麦克风。

!---更新--->

我编写了一个简单的C#Web服务器,该服务器侦听端口843,并提供上述策略-但是效果很好,但是,当使用SecureSocket连接进行安全连接(即打开HTTPS / SSL协议的套接字)时-使用主机证书对发送的请求进行加密。 据我所知,没有办法通过外部应用程序监听或获取服务器证书并解密数据,因此,唯一的方法是在通过适当的请求发送后以某种方式“教导” Apache使用跨域策略进行响应。适当的端口。

我有另一个想法是读取存储在Apache目录中的服务器证书文件,而不管服务器本身发生了什么,尽管imo实在是太过分了。

很想听听您的意见,

麦克风。

所以这就是我最终解决它的方法:

我已经使用了这些代码进行了一些修改: http : //www.switchonthecode.com/tutorials/csharp-tutorial-simple-threaded-tcp-server

并创建了一个简单的多线程Web服务器,该服务器侦听端口843,并根据适当的闪存请求提供了某种通用策略。

Adobe提供了几个示例,但是由于某些原因,Windows不喜欢这些示例。

还要注意,如果您使用的是Flash的SecureSocket对象,则应该使用目标服务器(IIS'/ Apaches'/ Tomcats'等。)SSL凭据,并将使用目标服务器证书的公钥启动客户端身份验证。 ,再说一次,虽然我已经开始使用C#的SSL流来实现一个代码,但到目前为止可能还没有任何运气,所以它可能不支持SSL。 如果您可以通过SSL进行操作,请告诉我。

希望这段代码对您有所帮助,

麦克风。

using System;
using System.Text;
using System.Net.Sockets;
using System.Threading;
using System.Net;
using System.IO;

namespace TCPSexyServer
{
    class Server
{
    private TcpListener tcpListener;
    private Thread listenThread;

    private void ListenForClients(int p)
    {
        throw new NotImplementedException();
    }

    public Server()
    {
        this.tcpListener = new TcpListener(IPAddress.Any, 843);
        this.listenThread = new Thread(new ThreadStart(ListenForClients));
        this.listenThread.Start();
    }

    private void ListenForClients()
    {
        this.tcpListener.Start();

        while (true)
        {
            //blocks until a client has connected to the server
            TcpClient client = this.tcpListener.AcceptTcpClient();

            //create a thread to handle communication 
            //with connected client
            Thread clientThread = new Thread(new ParameterizedThreadStart(HandleClientComm));
            clientThread.Start(client);
        }
    }

    private void HandleClientComm(object client)
    {
        TcpClient tcpClient = (TcpClient)client;
        NetworkStream clientStream = tcpClient.GetStream();
        byte[] message = new byte[4096];
        int bytesRead;

        while (true)
        {
            bytesRead = 0;

            try
            {
                //blocks until a client sends a message
                bytesRead = clientStream.Read(message, 0, 4096);
            }
            catch
            {
                //a socket error has occured
                break;
            }

            if (bytesRead == 0)
            {
                //the client has disconnected from the server
                break;
            }

            //message has successfully been received

            UTF8Encoding encoder = new UTF8Encoding();

            string sentData = encoder.GetString(message, 0, bytesRead);
            Console.WriteLine(sentData);
            if (sentData == "<policy-file-request/>\0")
            {
                String policy = "<?xml version=\"1.0\"?>\n" +
                                "<!DOCTYPE cross-domain-policy SYSTEM \"/xml/dtds/cross-domain-policy.dtd\">\n" +
                                "<cross-domain-policy>\n" +
                                "<site-control permitted-cross-domain-policies=\"master-only\"/>\n" +
                                "<allow-http-request-headers-from domain=\"*\" headers=\"*\" secure=\"true\" />\n" +
                                "<allow-access-from domain=\"*\" to-ports=\"*\" />\n" +
                                "</cross-domain-policy>\0";
                byte[] buffer = encoder.GetBytes(policy);
                clientStream.Write(buffer, 0, buffer.Length);
                clientStream.Flush();
                Console.WriteLine(policy);
            }
            else
            {
                tcpClient.Close();
            }
            System.Diagnostics.Debug.WriteLine(encoder.GetString(message, 0, bytesRead));
        }

        tcpClient.Close();
    }

        public static void Main(string[] args)
        {
            Server blah = new Server();
       }

    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM