如何通过 Silverlight 访问 REST API(使用基本身份验证)?
我正在尝试通过 silverlight 应用程序访问普通的 REST API,但似乎无法使基本身份验证正常工作(使用 silverlight 4.0)。
我正在使用 .NET WebClient,并使用有效的用户名/密码(对于 API)设置 webclient.Credentials。
我遇到两个主要错误:
System.NotSupportedException:BrowserHttpWebRequest 不支持自定义凭据。 (只有当我将 webclient.UseDefaulCredentials 设置为 false 时才会发生这种情况)
和
System.NotImplementedException:此类未实现此属性。 在 System.Net.WebRequest.set_Credentials(ICredentials 值) (当 webclient.UseDefaultCredentials 根本没有设置时发生)
我在这里错过了什么? Silverlight 4.0 仍然不支持基本身份验证吗?
I'm trying to access a run-of-the-mill REST API through a silverlight application, but can't seem to get basic authentication to work (using silverlight 4.0).
I'm using a .NET WebClient, and setting the webclient.Credentials with a valid username/password (for the API).
I'm running into two main errors:
System.NotSupportedException: BrowserHttpWebRequest does not support custom credentials.
(this only occurs when I set the webclient.UseDefaulCredentials to false)
and
System.NotImplementedException: This property is not implemented by this class.
at System.Net.WebRequest.set_Credentials(ICredentials value)
(occurs when webclient.UseDefaultCredentials isn't set at all)
what am I missing here? Is basic auth still not supported in Silverlight 4.0?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里有一篇关于它的文章 http:// /mark.mymonster.nl/2009/12/02/silverlight-4-credentials-weve-got-it/ 看起来神奇的线条是:
就我而言,它似乎发送凭据,但我仍然遇到 401 错误,但我只是抓住了我的一台 Web 服务器来尝试,它可能配置不正确,但这似乎应该可以工作。
There is an article about it here http://mark.mymonster.nl/2009/12/02/silverlight-4-credentials-weve-got-it/ and it seems the magic line is:
In my case it seems to send the credentials, but I still end up with a 401 error but I just grabbed one of my web servers to try and it may not be configured correctly, but this seems like it should work.
我还建议尝试开源库 Hammock for REST 它为许多现代网络提供了一个非常有用的包装器REST 和 oAuth 等调用。
I would also suggest trying the open source library Hammock for REST It provides a very useful wrapper around a lot of modern web calls like REST and oAuth.