2012-02-20 70 views
0

我怎樣才能在發送到特定端口的連接基於Apache服務器在上XAMPP/WAMP自定義請求自定義響應?XAMPP/WAMP基於Apache服務器的自定義回覆

我想回復\ 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應要求答覆。

任何方法/實現正確的回覆的方式可以理解,

與問候,

邁克。

---更新--->

我寫的監聽端口843,並提供上述政策的一個簡單的C#的Web服務器 - 使用一個的SecureSocket連接時,它的工作就好了,但是一個安全連接(即打開一個HTTPS/SSL協議的套接字) - 使用主機證書加密發送的請求。據我所知,有沒有聽或獲取服務器證書,並通過外部應用程序,因此解密數據的方式,唯一的辦法就是以某種方式「教」阿帕奇與跨域策略應對適當的請求被通過發出後適當的端口。

另一個想法我已經是讀取存儲在無論在服務器上發生的事情在Apache目錄服務器的證書文件,但國際海事組織這是一個矯枉過正。

很想聽聽您的意見,

Mike。

回答

0

因此,這裏是我如何最終解決它:

我用這個傢伙有一些修改代碼:http://www.switchonthecode.com/tutorials/csharp-tutorial-simple-threaded-tcp-server

,並創建一個監聽端口843簡單的多線程Web服務器,並提供了一個略顯一般政策在適當的閃光請求。

有Adobe提供的幾個例子,但由於某些原因,窗戶不喜歡這些。

另請注意,如果您使用的是Flash的SecureSocket對象,則應據稱使用目標服務器(IIS'/ Apaches'/ Tomcats'etc ..)SSL憑據並啓動客戶端身份驗證,使用公鑰目標服務器證書,然後再次,它可能不會這樣的代碼沒有SSL支持,雖然我已經開始實施一個使用C#的SSL流,迄今沒有任何運氣。如果您可以通過SSL工作,請告訴我。

希望這段代碼有幫助,

Mike。

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(); 
     } 

    } 
}