使用HttpWebRequest
,我使用以下代码来请求 soap 并获取流:
XmlDocument soapEnvelopeXml = new XmlDocument();
HttpWebRequest webRequest = ...
using (Stream stream = webRequest.GetRequestStream())
{
soapEnvelopeXml.Save(stream);
}
虽然这是错误消息:
Either ContentLength must be set to a non-negative number, or SendChunked set to true in order to perform the write operation when AllowWriteStreamBuffering is disabled.
如上面的消息所述,我无法写入流,因为如果我调用 save soapEvelopeXml,应用程序就会结束。
要解决此错误,只需在 HttpWebRequest 对象中启用一个参数。
webRequest.AllowWriteStreamBuffering = true;
该参数是对象属性的一部分,并引用了有关 learn.microsoft.com 的文档
AllowWriteStreamBuffering :获取或设置一个值,该值指示是否缓冲发送到 Internet 资源的数据