在C# .Net 4.5中使用this code连接到我的IP摄像机上的OnVif服务。
在这段代码的旁边,我尝试获取设备信息,如下所示:
string str = client.GetDeviceInformation(out model, out firmware, out serial, out hardwareId);
并阻止了这个错误:
An exception of type 'System.ServiceModel.Security.MessageSecurityException' occurred in mscorlib.dll but was not handled in user code
Additional information: The HTTP request is unauthorized with client authentication scheme 'Digest'. The authentication header received from the server was 'Basic realm="CBBA"'.
我试过this information about Basic realm了。通过向具有值Basic realm="Our Site"
的请求添加Http报头WWW-Authenticate
。但没那么走运。
那是什么玩意?如何修复它?
发布于 2014-02-26 21:59:01
您可能无法处理Digest Authentication。为了正确处理这些事情,您应该发送一个请求到一个非摘要的ONVIF方法,而不使用身份验证,既不使用PRE_AUTH
也不使用ws-usernameToken。
您可以获得以下两个答案之一:
通过env:Sender ter:NoAuthorized
,你会得到一个500的响应,这意味着摄像头不支持 digest (事实上,对于profile S设备,这不是强制的)。在这种情况下,您只能使用WS-UsernameToken
WWW-Authenticate
报头的401响应。在这种情况下,您应该遵循RFC 2617,评估所有必要的元素,并使用Authorization
标头重新发送请求。请记住,HTTP摘要challange总是由摄像机启动的,您不能只将其添加到第一个请求中。
查看§5.12的Core specification,至少要知道是否有摄像头处理身份验证。
发布于 2014-02-28 21:22:29
我有一个relevant issue -我必须使用ONVIF相机进行身份验证,我不知道身份验证HTTP的身份验证模式(基本/摘要)。在我的回答中,你可以看到如何正确地迭代所有的HTTP身份验证方案,或者你可以只使用Digest的代码,希望它能有所帮助。
https://stackoverflow.com/questions/21933515
复制相似问题