-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compatibility to net472, moved code to separate class
- Loading branch information
hannesmayer
committed
Nov 18, 2018
1 parent
0d1b606
commit 9818279
Showing
3 changed files
with
51 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,10 @@ | ||
namespace ReconnectFritz | ||
{ | ||
using System.IO; | ||
using System.Net; | ||
using System.Text; | ||
|
||
class Program | ||
{ | ||
private static 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>"; | ||
|
||
static void Main(string[] args) | ||
{ | ||
ReconnectFritzBox(); | ||
} | ||
|
||
private static 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; | ||
new FritzReconnect().ReconnectFritzBox(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters