HTTP Post XML文档 - 服务器只接收第一行 [英] HTTP Post XML document - server receives only first line
问题描述
我有C#应用程序,它通过HTTPS Post将XML文档发送到服务器。问题是服务器只接收第一行<?xml version =1.0encoding =UTF-8?>
。这是我的代码的截断版本(仅限重要部分)。什么可能导致这个问题?我的代码中是否有修改?
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连接,并且我收到的消息是文档类型不被接受。
SSL connectivity to the server has been assured, and the message I recevie in return is "document type not accepted".
谢谢!
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();
推荐答案
事实证明这些行是
loHttp.SendChunked = true;
loHttp.TransferEncoding =7bit;
不需要。
It turns out the lines
loHttp.SendChunked = true;
loHttp.TransferEncoding = "7bit";
weren't needed.
这篇关于HTTP Post XML文档 - 服务器只接收第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!