Hi,

I wrote down a small function to login on my IP Phone from the PC sending a POST string to the CallManager (with Extension Mobility) using the HttpWebRequest object...

Take a look to "Cisco Extension Mobility API" and please check upper/lower case in the post string of code below... something can be wrong!


private static void PostToService()
{
bool ERROR = false;

// Our string to be posted
// I used AppSettings to store my userID, pincode and phoneaddress
// You can change this as your desire
byte[] buffer = Encoding.ASCII.GetBytes("xml="+ConfigurationManager.AppSettings["userID"]+""+ConfigurationManager.AppSettings["pincode"]+""+ConfigurationManager.AppSettings["phoneaddress"]+""+ConfigurationManager.AppSettings["userID"]+"");

// HERE change A.B.C.D with the ip of your Call Manager
// ATTENTION there's no connection test, if cannot connect to server, it crash!
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create("http://A.B.C.D/emservice/EMServiceServlet");
WebReq.Method = "POST";
WebReq.ContentType = "application/x-www-form-urlencoded";
WebReq.ContentLength = buffer.Length;
Stream PostData = WebReq.GetRequestStream();
PostData.Write(buffer, 0, buffer.Length);
PostData.Close();
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
Console.WriteLine(WebResp.StatusCode);
Console.WriteLine(WebResp.Server);
Stream Answer = WebResp.GetResponseStream();
StreamReader _Answer = new StreamReader(Answer);

/* Response interpretation */
try
{
XmlTextReader objXmlTextReader = new XmlTextReader(Answer);

while (objXmlTextReader.Read())
{
switch (objXmlTextReader.NodeType)
{
case XmlNodeType.Element:
switch (objXmlTextReader.Name)
{
case "success":
Console.WriteLine("==> Login successfully <==");
break;
case "failure":
Console.WriteLine("==> Login Failed <==");
ERROR = true;
break;
}

while (objXmlTextReader.MoveToNextAttribute())
if (ERROR == true)
{
Console.Write("Error code: " + objXmlTextReader.Value + "\n");
}
break;
case XmlNodeType.Text:
if (ERROR)
{
Console.Write("Error Message: ");
Console.Write(objXmlTextReader.Value + "\n");
}
break;
}
}
}
catch (Exception ex)
{
Console.WriteLine("==> Error Parsing Output <==");
Console.WriteLine(ex.ToString());
}
Answer.Close();

Console.WriteLine("Disconnected");
}