次の方法を使用して、Webサイトから応答ストリームを取得しています-
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)