Uri AastraPhoneIP = new Uri ("http://123.122.20.120");
1. Methode mit Anmeldeversuch
private async void sendToPhone (String Message)
{
var userName = "Admin";
var passwd = "22222";
HttpClient httpClient = new HttpClient();
var authToken = Encoding.ASCII.GetBytes($"{userName}:{passwd}");
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",Convert.ToBase64String(authToken));
String someXmlString = "xml=" + AAstraTelefonReply(new string[] { "Test" }).Trim();
var stringContent = new StringContent(someXmlString, Encoding.UTF8, "text/xml");
var respone = await httpClient.PostAsync(AastraPhoneIP, stringContent);
var responseString = await respone.Content.ReadAsStringAsync();
if (!respone.IsSuccessStatusCode)
{
throw new Exception(string.Format("Invalid uri: {0}", AastraPhoneIP));
}
}
2. Methode ohne Anmeldeversuch
void sendToPhone2()
{
var request = (HttpWebRequest)WebRequest.Create(AastraPhoneIP);
// var postData = "xml=" + Uri.EscapeDataString(AAstraTelefonReply(new string[] { "Test" }).Trim());
var postData = "xml=" + AAstraTelefonReply(new string[] { "Test" }).Trim();
var data = Encoding.ASCII.GetBytes(postData);
request.Method = "POST";
//request.ContentType = "application/x-www-form-urlencoded";
request.ContentType = "text/xml";
request.ContentLength = data.Length;
request.KeepAlive = true;
request.Host = "10.200.10.122";
request.Referer = "10.200.10.51";
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
}
public string AAstraTelefonReply(String[] Message)
{
String Return = "";
// Return += "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
Return += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
Return += "<AastraIPPhoneFormattedTextScreen dstroyOnExit = \"yes\">";
Return += "<Scroll Height=\"2\">";
for (int i = 0; i < Message.Length; i++)
if (Message[I] != null) Return += "<Line>" + Message[I] + "</Line>";
//if (Message[2] != null) Return += "<Line Size=\"double\">" + Message[2] + "</Line>";
//if (Message[3] != null) Return += "<Line Align=\"center\">" + Message[3] + "</Line>";
Return += "</Scroll>";
Return += "</AastraIPPhoneFormattedTextScreen>";
return Return;
}[/I][/I]