F
fahd
Hi,
I'm trying to run a ccxml, and consequently, a voiceXML page on the
voice server through my application and the documentation of the
server mention that it can be done using HTTP POST.
Following is a sample example of html that works and successfully
starts a ccxml page on a remote destination
<html>
<body>
<form method="post" action="http://localhost:4045/basichttp"
enctype="application/x-www-form-urlencoded">
ID="Form1">
name: <input type="text" name="name" size="40"
value="OutBoundCallEvent" id="Text1" />
URI to be contacted by the outbound: <input type="text"
name="ToBeContacted_URI" size="52" value="10.2.50.42" id="Text5" />
VoiceXML URI: <input type="text" name="VoiceXML_URI" size="73"
value="file:///C:/voiceXML/three.vxml">
ID="Text6" />
CCXML URI: <input type="text" name="uri" size="75" value="file:///
C:/CCXML/outboundcall.ccxml">
ID="Text7" />
<input type="submit" id="Submit1" name="Submit1">
</input></input></input></form>
</body>
</html>
Now I want to achieve the same effect through my c# application and I
am using HttpRequest and HttpResponse to mimic submitting the form
above.
following is my attempt on this
string uri = @"http://localhost:4045/basichttp";
string data =
@"name=OutBoundCallEvent&ToBeContacted_URI=10.2.50.42&VoiceXML_URI=file:///
C:/voiceXML/three.vxml&uri=file:///C:/CCXML/outboundcall.ccxml";
byte [] bytes = System.Text.Encoding.ASCII.GetBytes(data);
HttpWebRequest req = (HttpWebRequest) WebRequest.Create(uri);
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
req.ContentLength = bytes.Length;
System.IO.Stream os = req.GetRequestStream();
os.Write (bytes, 0, bytes.Length);
os.Close();
HttpWebResponse resp = (HttpWebResponse) req.GetResponse();
if (resp== null)
{
MessageBox.Show("Problem in sending response!");
}
System.IO.StreamReader sr = new
System.IO.StreamReader(resp.GetResponseStream());
string result = sr.ReadToEnd().Trim();
MessageBox.Show("All done!");
Now when I try to get the response using HttpResponse I get an error "
The remote server returned an error: (400) Bad Request."
Q1 Does writing the data into the stream means that the data has been
sent just like pressing the submit button? or does using the
getResponse method do this?
Q2 Is there something im missing in order to achieve a simple submit
function? I have tried sending some data over to an asp page and use
response like above and it all seems to work fine.
Any help will be greatly appreciated.
Kind Regards
Fahd
I'm trying to run a ccxml, and consequently, a voiceXML page on the
voice server through my application and the documentation of the
server mention that it can be done using HTTP POST.
Following is a sample example of html that works and successfully
starts a ccxml page on a remote destination
<html>
<body>
<form method="post" action="http://localhost:4045/basichttp"
enctype="application/x-www-form-urlencoded">
ID="Form1">
name: <input type="text" name="name" size="40"
value="OutBoundCallEvent" id="Text1" />
URI to be contacted by the outbound: <input type="text"
name="ToBeContacted_URI" size="52" value="10.2.50.42" id="Text5" />
VoiceXML URI: <input type="text" name="VoiceXML_URI" size="73"
value="file:///C:/voiceXML/three.vxml">
ID="Text6" />
CCXML URI: <input type="text" name="uri" size="75" value="file:///
C:/CCXML/outboundcall.ccxml">
ID="Text7" />
<input type="submit" id="Submit1" name="Submit1">
</input></input></input></form>
</body>
</html>
Now I want to achieve the same effect through my c# application and I
am using HttpRequest and HttpResponse to mimic submitting the form
above.
following is my attempt on this
string uri = @"http://localhost:4045/basichttp";
string data =
@"name=OutBoundCallEvent&ToBeContacted_URI=10.2.50.42&VoiceXML_URI=file:///
C:/voiceXML/three.vxml&uri=file:///C:/CCXML/outboundcall.ccxml";
byte [] bytes = System.Text.Encoding.ASCII.GetBytes(data);
HttpWebRequest req = (HttpWebRequest) WebRequest.Create(uri);
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
req.ContentLength = bytes.Length;
System.IO.Stream os = req.GetRequestStream();
os.Write (bytes, 0, bytes.Length);
os.Close();
HttpWebResponse resp = (HttpWebResponse) req.GetResponse();
if (resp== null)
{
MessageBox.Show("Problem in sending response!");
}
System.IO.StreamReader sr = new
System.IO.StreamReader(resp.GetResponseStream());
string result = sr.ReadToEnd().Trim();
MessageBox.Show("All done!");
Now when I try to get the response using HttpResponse I get an error "
The remote server returned an error: (400) Bad Request."
Q1 Does writing the data into the stream means that the data has been
sent just like pressing the submit button? or does using the
getResponse method do this?
Q2 Is there something im missing in order to achieve a simple submit
function? I have tried sending some data over to an asp page and use
response like above and it all seems to work fine.
Any help will be greatly appreciated.
Kind Regards
Fahd