I have C# application that sends an XML document to a server via HTTPS Post. The problem is that the server receives only the first line <?xml version="1.0" encoding="UTF-8"?>
. Here is a truncated version of my code (important parts only). What could be causing this problem? Is there modify in my code?
SSL connectivity to the server has been assured, and the message I recevie in return is "document type not accepted".
thanks!
StreamWriter loPostData = null;
HttpWebRequest loHttp = null;
HttpWebResponse loWebResponse = null;
byte[] buffer;
String uri = ConfigurationSettings.AppSettings["URL"];
loHttp = (HttpWebRequest)WebRequest.Create(uri);
buffer = Encoding.ASCII.GetBytes(payload);
//Request Header
loHttp.ProtocolVersion = HttpVersion.Version11;
loHttp.KeepAlive = true;
loHttp.Accept = "text/xml;charset=\"utf-8\"";
loHttp.Method = WebRequestMethods.Http.Post;
loHttp.ContentType = "text/xml;charset=\"utf-8\"";
loHttp.ContentLength = buffer.Length;
loHttp.SendChunked = true;
loHttp.TransferEncoding = "7bit";
loHttp.AllowWriteStreamBuffering = true;
ServicePointManager.ServerCertificateValidationCallback += delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true; // **** Always accept return
};
X509Certificate x509_1 = new X509Certificate(ConfigurationSettings.AppSettings["OPEN_INVOICE_CERTIFICATE"]);
loHttp.ClientCertificates.Add(x509_1);
//Send data
loPostData = loHttp.GetRequestStream();
loPostData.Write(buffer, 0, buffer.Length);
loPostData.Close();
//Get a response
loWebResponse = (HttpWebResponse)loHttp.GetResponse();
StreamReader responsestream = new StreamReader(loWebResponse.GetResponseStream());
String rsp = responsestream.ReadToEnd();
responsestream.Close();
Based on the error message you are getting, are you sure that the page you are calling REALLY wants the content type to be text/xml? It might be that you need to post it like a standard webrequest instead of posting an HTML file directly by content type.
It turns out the lines
loHttp.SendChunked = true;
loHttp.TransferEncoding = "7bit";
weren't needed.