-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFritzReconnect.cs
49 lines (43 loc) · 1.94 KB
/
FritzReconnect.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
namespace ReconnectFritz
{
using System.IO;
using System.Net;
using System.Text;
public class FritzReconnect
{
private string xmldata = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope\">" +
"<s:Body>" +
"<u:ForceTermination xmlns:u=\"urn:schemas-upnp-org:service:WANIPConnection:1\" />" +
"</s:Body>" +
"</s:Envelope>";
public string ReconnectFritzBox()
{
string resulXmlFromWebService = null;
var webRequest = WebRequest.Create("http://fritz.box:49000/igdupnp/control/WANIPConn1");
var httpRequest = (HttpWebRequest)webRequest;
httpRequest.Method = "POST";
httpRequest.ContentType = "text/xml; charset=utf-8";
httpRequest.Headers.Add("SOAPACTION", "urn:schemas-upnp-org:service:WANIPConnection:1#ForceTermination");
httpRequest.ProtocolVersion = HttpVersion.Version11;
httpRequest.Credentials = CredentialCache.DefaultCredentials;
httpRequest.ContentLength = xmldata.Length;
using (var requestStream = httpRequest.GetRequestStream())
{
//Create Stream and Complete Request
using (var streamWriter = new StreamWriter(requestStream, Encoding.ASCII))
{
streamWriter.Write(xmldata);
streamWriter.Close();
//Get the Response
var wr = (HttpWebResponse)httpRequest.GetResponse();
using (var srd = new StreamReader(wr.GetResponseStream()))
{
resulXmlFromWebService = srd.ReadToEnd();
}
}
}
return resulXmlFromWebService;
}
}
}