flutter app connect to ip camera with digest auth

青春壹個敷衍的年華 提交于 2020-01-16 19:31:33

问题


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}

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\"";

I create this:

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

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);
         });

and getting this error:

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

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

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

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

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 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.

screenshot of Android studio with error


回答1:


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.



来源:https://stackoverflow.com/questions/59491178/flutter-app-connect-to-ip-camera-with-digest-auth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!