我有以下代码进行调用,然后返回xml:
public MainWindow(IModuleCatalog moduleCatalog, IModuleManager moduleManager)
{
InitializeComponent();
this.DataContext = this;
this.ConfirmationRequest = new InteractionRequest<IConfirmation>();
this.moduleCatalog = moduleCatalog;
this.moduleManager = moduleManager;
UpdateModulesList();
this.Loaded += (s, e) => this.chWindow.Show();
}
大部分时间(并非总是)我得到
抛出异常。System.Net.WebException:服务器提交了协议违规。
Section = ResponseStatusLine at System.Net.HttpWebRequest.GetResponse()
我已直接在private string Send(string url)
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (Stream stream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}
}
}
catch (WebException ex)
{
var _status = ex.Status.ToString();
if (ex.Status == WebExceptionStatus.ProtocolError)
{
_status = ((HttpWebResponse)ex.Response).StatusCode.ToString();
}
Trace.WriteLine(_status.ToString());
}
return "error";
}
部分将此添加到我的App.config中:
<configuration>
但我仍然得到错误。
答案 0 :(得分:2)
集
request.KeepAlive = false;
此外,如果您尝试通过此问题,则粘贴的useUnsafeHeaderParsing配置值将其设置为false,如果您将其设置为true。
答案 1 :(得分:0)
newInstance