2017-01-17 5 views
1

C#を使用してAVM FritzBox 7270ルータにSOAPリクエストを送信する方法を学んでいます。Tr064リクエストをAVM FritzBoxに送信する7270

private string Execute(string controlUrl, string serviceType, string action) 
    { 
     WebRequest webRequest = WebRequest.Create("http://fritz.box:49000" + controlUrl); 
     HttpWebRequest httpRequest = (HttpWebRequest)webRequest; 
     httpRequest.Method = "POST"; 
     httpRequest.ContentType = "text/xml; charset=utf-8"; 
     httpRequest.Headers.Add("SOAPACTION", string.Format("{0}#{1}", serviceType, action)); 
     httpRequest.ProtocolVersion = HttpVersion.Version11; 
     httpRequest.Credentials = new NetworkCredential("username", "password"); 
     Stream requestStream = httpRequest.GetRequestStream(); 

     StreamWriter streamWriter = new StreamWriter(requestStream, Encoding.ASCII); 

     streamWriter.Write(GetBody(serviceType, action)); 
     streamWriter.Close(); 
     //Get the Response  
     try 
     { 
      HttpWebResponse wr = (HttpWebResponse)httpRequest.GetResponse(); 
      StreamReader srd = new StreamReader(wr.GetResponseStream()); 
      return srd.ReadToEnd(); 
     } 
     catch (WebException) 
     { 
      return null; 
     } 
    } 

機能GetBody:ルータにSOAPリクエストを送信する私の方法イストここ

private string GetBody(string serviceType, string action) 
    { 
     const string fmt = @"<?xml version=""1.0"" encoding=""utf-8""?> 
<s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/"" s:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/""> 
    <s:Body> 
    <u:{0} xmlns:u=""{1}"" /> 
    </s:Body> 
</s:Envelope> 
";   
      return string.Format(fmt, action, serviceType); 
     } 
    } 

私はインターネットのどこにでも見られるパラメータで、このメソッドをテスト

controlUrl = "/upnp/control/WANIPConn1" 
serviceType = "urn:schemas-upnp-org:service:WANIPConnection:1" 
action = "GetExternalIPAddress" 

これはうまくいきます。

はしかし、私は公式の道を行くと、最初に私の実際のルータのための有効なパラメータを受信するための要求

http://fritz.box:49000/tr64desc.xml 

を送るべきだと思います。私は、次のノードを見つけ、この要求に応じて:

<service> 
    <serviceType>urn:dslforum-org:service:WANIPConnection:1</serviceType> 
    <serviceId>urn:WANIPConnection-com:serviceId:WANIPConnection1</serviceId> 
    <controlURL>/upnp/control/wanipconnection1</controlURL> 
    <eventSubURL>/upnp/control/wanipconnection1</eventSubURL> 
    <SCPDURL>/wanipconnSCPD.xml</SCPDURL> 
</service> 

いるServiceIDとcontrolUrlのため、これらの値を使用して、私はエラー500(内部サーバーエラー)を取得します。

誰が私を助けることができますか?私のコードで何が間違っていますか?

がFritz.Boxのundocumeted機能の多くがあるように思われる、と私はインターネットで見つけpararmetersはoviously thease機能の一部です:

+0

これはデバイスのバグかもしれませんが、どうすればhttp://fritz.box:49000/tr64desc.xmlを使用するべきなのか分かりますか?実際にSSDP発見からそれを得ていますか? – jku

答えて

1

は、私は問題が解決されると思います。

<service> 
    <serviceType>urn:dslforum-org:service:WANPPPConnection:1</serviceType> 
    <serviceId>urn:WANPPPConnection-com:serviceId:WANPPPConnection1</serviceId> 
    <controlURL>/upnp/control/wanpppconn1</controlURL> 
    <eventSubURL>/upnp/control/wanpppconn1</eventSubURL> 
    <SCPDURL>/wanpppconnSCPD.xml</SCPDURL> 
</service> 

私は問題なく

GetExternalIPAddress 

を呼び出すことができます。

関連する問題