1

不太确定为什么我会收到异常.. 代码是健全的,API 正在通过我的浏览器工作。

var url = new Uri("http://octopart.com/api/search?keywords=" + topic.Text);
        WebClient octopartCall = new WebClient();
        octopartCall.OpenReadCompleted += new OpenReadCompletedEventHandler(Octopart_Completed);
        octopartCall.OpenReadAsync(url);
 if (e.Error == null)
        ... error is not null so I throw the message below  

System.Exception 发生 Message=System.Security.SecurityException ---> System.Security.SecurityException:安全错误。在 System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) 在 System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.b__4(Object sendState) 在 System.Net.Browser.AsyncHelper.<>c__DisplayClass2.b__0(Object sendState) --- 内部异常堆栈跟踪结束 --- System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state) 在 System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) 在 System.Net.WebClient。 GetWebResponse(WebRequest request, IAsyncResult result) at System.Net.WebClient.OpenReadAsyncCallback(IAsyncResult result) StackTrace: at Register.Page.Octopart_Completed(Object sender,

4

2 回答 2

2

内置 Web 服务器的 Visual Studio 无法处理跨域连接。

解决方案 1:为您的项目创建一个新的虚拟目录并在 IIS 中运行 解决方案 2:将 crossdomain.xml 配置文件添加到您的网站项目中,其中包含

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM
     "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>  
    <allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>
于 2009-07-27T05:04:11.243 回答
0

在哪里error设置?在Completed处理程序中?

如果是这种情况,那么您的问题可能是处理程序尚未完成。

此外,您可能需要对您的 URL 进行 URL 编码,因为您正在向其中添加任意文本。

最后,这是在哪里运行?ASP.NET?银光?以及什么版本?

于 2009-07-27T03:55:11.257 回答