05-31-2005 11:38 AM - edited 03-15-2019 03:29 AM
Hello All
i'm trying to get the following code to post to a 7960 phone. i can sucessfully post using an asp page
and form set to post but getting ANY asp.net/dotnet code to post to phone is short of a small miracle
any help would be greatly appreciated
PhoneExecute("<CiscoIPPhoneExecute><ExecuteItem Priority=\"0\" URL=\"Dial:" + RemoveInputCharacters.SanitizeInput(PhoneNumber) + "\"/></CiscoIPPhoneExecute>","homer","simpson")
public string PhoneExecute(string xml,string userID, string password)
{
Response.Write("<div id='mydiv' >");
Response.Write("_");
Response.Write("</div>");
Response.Write("<script>mydiv.innerText = '';</script>");
Response.Write("<script language=javascript>;");
Response.Write("var dots = 0;var dotmax = 10;function ShowWait()");
Response.Write("{var output; output = 'Dialing: " + PhoneNumber + "';dots++;if(dots>=dotmax)dots=1;");
Response.Write("for(var x = 0;x < dots;x++){output += '.';}mydiv.innerText = output;}");
Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible';window.setInterval('ShowWait()',1000);}");
Response.Write("function HideWait(){mydiv.style.visibility = 'hidden';window.clearInterval();}");
Response.Write("StartShowWait();</script>");
Response.Flush();
Thread.Sleep(10000) ;
xml = "XML=" + Server.UrlEncode(xml);
//string xml = "XML=<CiscoIPPhoneText><Title>Alert</Title><Prompt>Your current options</Prompt><Text>Test it now</Text></CiscoIPPhoneText>";
string url = "http://127.0.0.1/CGI/Execute";
//string url = "http://127.0.0.1/ciscoipservices/requestsniffer.asp";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(xml);
string authstring = text2base64.Encode(userID + ":" + password);
byte[] bytes = encoding.GetBytes(authstring);
HttpWebRequest xmlhttp = (HttpWebRequest)WebRequest.Create(url);
xmlhttp.Method = "POST";
xmlhttp.ContentType="application/x-www-form-urlencoded";
xmlhttp.ContentLength = data.Length;
xmlhttp.Headers.Add("Authorization", "Basic " + authstring);
Stream requestStream = xmlhttp.GetRequestStream();
requestStream.Write(data, 0, data.Length);
HttpWebResponse myHttpWebResponse = (HttpWebResponse)xmlhttp.GetResponse();
Stream receiveStream = myHttpWebResponse.GetResponseStream();
StreamReader readStream = new StreamReader(receiveStream, encoding);
Char[] read = new Char[256];
int count = readStream.Read( read, 0, 256 );
StringBuilder sb = new StringBuilder();
while (count > 0)
{
String str = new String(read, 0, count);
sb.Append( str);
count = readStream.Read(read, 0, 256);
}
requestStream.Close();
receiveStream.Close();
readStream.Close();
myHttpWebResponse.Close();
string responseData = sb.ToString ();
return responseData;
}
05-31-2005 01:46 PM
Try setting the headers Keep-Alive = 300 and Connection = keep-alive, and the version to 1.1. I only say that because a web browser does the same when you post to a phone. If that doesn't work, I would just replicate all the headers a browser sends when posting to the phones, and work back from there.
You should know however that we have had quite a few problems with .NET HttpWebRequest and the Cisco IP Phones. It can be made to work, however! there seems to be a bug in the phones in that they violate the HTTP spec. The .NET HttpWebRequest class then bails out when this occurs, ruining your request. This exception won't occur everytime... it is definitely a timing/race condition, and there seems to be no workaround if you use HttpWebRequest to do the heavy-lifting.
(I had to get out ethereal to verify and compare what the phone was doing to the HTTP spec, but .NET seemed to be right in that it was violating HTTP 1.0). It's too bad the HttpWebRequest is so strict.
05-31-2005 02:46 PM
hello all,
well i found the problem which was that the server was sending a header "Expect: 100-Continue" and the initial request form data was not being sent
so i used
ServicePointManager.Expect100Continue = false;
and the request worked perfectly
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide