我正在使用以下方法从网站获取响应流 -
HttpWebRequest request;
WebResponse response;
private void button1_Click(object sender, RoutedEventArgs e)
{
string url = textBox1.Text;
request = WebRequest.Create(url) as HttpWebRequest;
request.BeginGetResponse(AfterRequest, null);
}
public void AfterRequest(IAsyncResult result)
{
response = request.EndGetResponse(result);
using (StreamReader sd = new StreamReader(response.GetResponseStream()))
{
string resultString = sd.ReadToEnd();
}
response.Close();
}
但是,代码在到达时会中断-
response = request.EndGetResponse(result);
带有错误消息 -
SecurityException was unhandled by user code
是什么导致了这个问题?
听到是完全例外 -
System.Security.SecurityException ---> System.Security.SecurityException: Security error.
at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClassa. <EndGetResponse>b__9(Object sendState)
at System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__1(Object sendState)
--- End of inner exception stack trace ---
at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)
at System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult result)