2

我正在尝试将带有 GET 请求的 JSON 列表加载到我的 localhost(WAMP)上的 PHP 文件到我的 Silverlight+Webproj 解决方案中:

HttpWebRequest request = WebRequest.Create(uri) as HttpWebRequest;
request.BeginGetRequestStream(GetRequestStreamCallback, request);

    private void GetRequestStreamCallback(IAsyncResult asynchronousResult)
    {
        HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
        Stream postStream = request.EndGetRequestStream(asynchronousResult);

        byte[] byteArray = Encoding.UTF8.GetBytes(postInformation);
        postStream.Write(byteArray, 0, postInformation.Length);
        postStream.Close();
        request.BeginGetResponse(DownloadCompleted, request);
    }

    private void DownloadCompleted(IAsyncResult asynchronousResult)
    {
        ... load the data from the response , etc
}

这对另一个网站以完全相同的方式工作得非常好。但现在我得到了这个安全异常:

{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__0(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 KunstWebsite.Model.Factory`1.DownloadCompleted(IAsyncResult asynchronousResult)}

我尝试了我发现的解决方案,例如添加 clientaccesspolicy.xml、crossdomain.xml、将 localhost 作为受信任站点、将 trust level="Full" 添加到我的 web.config。似乎都没有工作...

有人知道我可能忽略了什么吗?

4

0 回答 0