soap - HttpWebRequest 500 内部错误,但 SOAPUI 有效
问题描述
我收到一个错误“远程服务器返回错误:(500) 内部服务器错误。” 状态码为“ProtocolError”
HttpWebRequest webRequest = null;
XmlDocument soapEnvelopeXml = new XmlDocument();
string requestEnvelopeString = SerializerHelper.ToRequestEnvelopeString(request);
soapEnvelopeXml.LoadXml(requestEnvelopeString);
webRequest = (HttpWebRequest)WebRequest.Create(<<endpointUrl>>);
webRequest.ContentType = "text/xml;charset=\"utf-8\"";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
webRequest.KeepAlive = true;
webRequest.ProtocolVersion = HttpVersion.Version11;
using (Stream stream = webRequest.GetRequestStream())
{
soapEnvelopeXml.Save(stream);
}
try
{
using (WebResponse webResponse = webRequest.GetResponse())
{
using (StreamReader reader = new StreamReader(webResponse.GetResponseStream()))
{
string responseEnvelopeString = reader.ReadToEnd();
}
}
}
catch (WebException ex)
{
string exMessage = ex.Message;
}
当我直接通过 SOAPUI 发送 requestEnvelopeString 时,它可以工作,有人可以建议如何解决这个问题吗?
解决方案
发现问题是缺少 SOAP-ACTION 标头,SOAPUI 会自动添加到请求中。
谢谢薄荷灵魂
推荐阅读
- docker - 从 RPi 到 TV 的 MiniDLNA(docker)流卡住/缓冲 .mkv 文件非常慢
- internationalization - 国际化:表示“旁白”的括号有多普遍?
- php - $update["message"]["text"] api 电报无法识别消息
- ios - 如何仅将 Xamarin.iOS 可执行文件发送给开发团队中的朋友
- java - DFS 查找子集的所有排列
- c# - 为什么使用 params 的 C# Attribute 不适用于我的类但适用于字符串?
- python - 如何从不同的子程序打印数组?我不太确定如何打印 myArray.. 我不断收到 NameError: name 'myArray' is not defined
- python-3.x - Python |S1 向量到字符串
- python - 使用 2D numpy 数组的每一行创建 1D numpy 数组的元组列表
- java - 如何使用 log4j2.properties 文件将不同级别的日志发送到不同的附加程序?