Flutter应用程序通过摘要身份验证连接到IP摄像机 [英] flutter app connect to ip camera with digest auth

查看:265
本文介绍了Flutter应用程序通过摘要身份验证连接到IP摄像机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在IP摄像机上传递摘要身份验证 我在Flutter上做,但实际上没关系. 我从状态码为401的摄像头收到HTTP响应 和标题:

I'm trying to pass digest auth on my ip camera I do it on Flutter but actually it doesn't matter. I got http response from camera with status code 401 Not Authorized and Headers:

{content-type: text/html, pragma: no-cache, cache-control: no-cache, www-authenticate: Digest 
realm="goAhead", domain=":13237",qop="auth", nonce="a98326cc6022c2a2b7cc7e57a5956f77", 
opaque="5ccc069c403ebaf9f0171e9517f40e41",algorithm="MD5", stale="FALSE", date: Thu Dec 26 16:31:43 
2019, server: GoAhead-Webs}

从此开始,在这里我找到了所需的Response构造函数视图,如下所示:

from this source here I've found the needed Response constructor view like this:

var mResponse = "Digest username=\"$username\", realm=\"$realm\", nonce=\"$nonce\", uri=\"$uri\", 
                response=\"$_response\", cnonce=\"$cnonce\", nc=$nc, qop=\"$qop\"";

我创建了这个:

Digest username="admin", realm="goAhead", nonce="a98326cc6022c2a2b7cc7e57a5956f77", 
uri="/onvif/device_service", response="5313fe5265efcd3da37cec322d92ebd7", cnonce="1234567890", 
nc=00000001, qop="auth"

并将http请求发送到相机:

and send http request to camera:

Future<http.Response> new_response = http.post(snapshotUrl, headers: {"Content-Type":"text/xml; charset=utf-8", "Authorization": mResponse }, body: mGetSnapshotUriAuth);
         new_response.then((resp){
           print(resp.statusCode);
         });

并收到此错误:

[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: Invalid header field name

当我删除标题的授权"字段时,摄像机将显示401代码. 我正在尝试从在Onvif协议上工作的IP摄像机获取快照.我不确定Uri参数. 当我尝试通过台式机截图

When I remove "Authorization" field of headers, camera response with 401 code. I'm trying to get snapshot from ip camera works on Onvif protocol. I am not sure in Uri parameter. The same error when I try send this http request via http Client on desktop machine screenshot

问题2 : 当我尝试将uri param更改为其他内容时,例如:

Question 2: When I try to change uri param to something else e.g:

String uri = http://www.onvif.org/ver10/media/wsdl/GetSnapshotUri";

我的相机停止回复我.当我开始使用Http嗅探器或更改Digest响应的字段名称时,可以看到相同的行为.有时,重置相机会有所帮助(甚至是硬重置),并且相机会再次开始工作(返回401错误),有时它会自行开始工作.但顺便说一下,相机可以通过其他Camera Viewer Apps继续工作. 我从http嗅探器获取的屏幕截图

My camera stops reply to me. The same behaviour I can see when I start use Http sniffer or change Digest's response's field name. Sometimes reset camera helps(or even hard reset) and it start working(return 401 error) again, sometimes it's start working by itself. But by the way the camera continues working via others Camera Viewer Apps. My screenshot from http sniffer

PS经过大量测试解决了这个问题后,我认为我的参数值是正确的,因为如果更改用户名,密码等内容(cnonce除外.当我更改nonce结果相同)时,我会收到另一个错误:401.

PS After many tests to solve this problem I think my param values are correct, because If change something e.g username, password and etc (except cnonce. When I change сnonce the result the same), I got other error: 401.

Android Studio出现错误的屏幕截图

推荐答案

手动编写SOAP请求是 BAD PRACTICE .我对dart一无所知,但我邀请您寻找gsoap之类的工具来从WSDL文件生成功能,您可以找到

Writing SOAP requests by hand is BAD PRACTICE. I know nothing about dart, but I invite you to look for a tool like gsoap for generating the functions from thw WSDL files you can find here. Don't write requests by hand, you'll end up in a mess when parsing the responses.

这篇关于Flutter应用程序通过摘要身份验证连接到IP摄像机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆