I am trying to send an xml formatted document that I create to a phone and I keep getting a response back of 301 XML document not valid. I went on the W3C website and tested the string and it seems fine... here it so people see it.
I was using php orgionally with cURL and here is what that looked like.
XMLData = urlencode($XMLData);
XMLData = Server(XMLData);
string XPost = "XMLData="+XMLData;
ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_URL,$URL); // set url to post to
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // store the return value as a string
// 1 is an acceptable value for TRUE.
curl_setopt($ch, CURLOPT_TIMEOUT, 4); // times out after 4s
curl_setopt($ch, CURLOPT_POSTFIELDS, $XPost); // add POST fields
$result = curl_exec($ch); // execute the process
curl_close($ch);
This worked ok, but it has been decided to go completely ASP.net / C# and I am now trying to convert this into an HTTPWebRequest where I am now getting this 303 error about the xml.
Below is my code for that
HttpWebRequest request = null;
string buf="";
string fullbuf="";
bool result = false;
try{
//string msgArg = "Call from Gregg";
string MESSAGE_SENDER_ADDRESS = System.Environment.MachineName;
string URL = "http://" + phoneIp + "/forms/push";
Log.WriteLine("Sending message to x"+phoneExtn+" ("+phoneIp+") --- ", Log.DEBUG_LEVEL.TERSE);
string XMLData = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><Push alert=\"1\" type=\"display\" mode=\"normal\" > <go href=\"http://" +
tps + "/"+ casName + "/" + appName + "/Messages/"+ fname + "\" method=\"get\"></go> </Push>";
// Build the push message
// Was XMLData = urlencode($XMLData);
//XMLData = Server(XMLData);
string XPost = "XMLData="+XMLData;
//string phoneextArg = "4061";
string message;
message = "http://" + phoneIp + "/forms/push";
byte[] bytes = Encoding.UTF8.GetBytes(XMLData);
request = (HttpWebRequest) WebRequest.Create(message);
request.Method = "POST";
request.ContentLength = bytes.Length;
request.ContentType = "text/xml";
request.Timeout = 600000;
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(bytes, 0, bytes.Length);
}
Log.WriteLine("Send Push: XMLData = " + XMLData, Log.DEBUG_LEVEL.TERSE);
}
catch (Exception ex)
{
Log.WriteLine( "Error from Send Push Request: " + ex.Message, Log.DEBUG_LEVEL.TERSE);
}
I have a response after this that shows the Response and the response in full ends up being
Push Status: 301 XML document not valid
Any help would be great. thanks!!