Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpException: Invalid response line #3

Closed
wmhseir3 opened this issue Oct 11, 2021 · 13 comments
Closed

HttpException: Invalid response line #3

wmhseir3 opened this issue Oct 11, 2021 · 13 comments

Comments

@wmhseir3
Copy link

hi, I tried the 0.0.9 with the following exception when making the ptz operation with one valid profileToken.

E/flutter (28604): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Exception: DioError [DioErrorType.other]: HttpException: Invalid response line, uri = http://192.168.1.103:2020/onvif/service
E/flutter (28604): #0 DioMixin.assureDioError (package:dio/src/dio_mixin.dart:819:20)
E/flutter (28604): #1 DioMixin._dispatchRequest (package:dio/src/dio_mixin.dart:678:13)
E/flutter (28604):
E/flutter (28604): #2 DioMixin.fetch.. (package:dio/src/dio_mixin.dart)
E/flutter (28604):
E/flutter (28604):
E/flutter (28604): #0 Soap.send (package:easy_onvif/src/soap.dart:34:7)
E/flutter (28604):
E/flutter (28604): #1 Soap.retrieveEnvlope (package:easy_onvif/src/soap.dart:43:26)
E/flutter (28604):
E/flutter (28604): #2 Ptz.continuousMove (package:easy_onvif/src/ptz.dart:30:5)
E/flutter (28604):
E/flutter (28604): #3 Ptz._zoom (package:easy_onvif/src/ptz.dart:192:5)
E/flutter (28604):
E/flutter (28604): #4 Ptz.zoomIn (package:easy_onvif/src/ptz.dart:203:5)

I do not have the response for you this time as it's null as with the error.
However, I attached the my debug screen capture for you to refer to which might be better than nothing.
ptz_error_screen

br,
William

@faithoflifedev
Copy link
Owner

Hi @wmhseir3, in this case can you give me some sample code for the operation you are trying to perform? It looks like the request might be the problem in this case, whereas in the past the code has had a problem with the response.

@wmhseir3
Copy link
Author

hi, here is my codes as followings. I commented it out the "profs = await easyOnvif.media.getProfiles();"as this is another issue in #4. I managed to find the the profileToken manually when calling the zoomIn which causing this issue #3.

if(index>=0) {
  _item =  _box.getAt(index);
  title = _item.name;
  _onvif = Onvif(
      host: _item.host,
      username: _item.username,
      password: _item.password,
  );
  await _onvif.initialize();
  //get device info
  var deviceInfo = await _onvif.deviceManagement.getDeviceInformation();
  //get device profiles
  // var profs = await _onvif.media.getProfiles();
  // var profileToken = profs[0].token;
  await _onvif.ptz.zoomIn(_item.profileToken);

br,
William

@faithoflifedev
Copy link
Owner

#5 should solve this issue as well.

@faithoflifedev
Copy link
Owner

easy_onvif 0.0.10 has been published to pub.dev, it included the PR for #5 , let me know if it resolves the issue so I can close this.

@wmhseir3
Copy link
Author

The 0.0.10 build still has the same issue and not solved. The captured DioError are as followings:
E/flutter (11958): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Exception: DioError [DioErrorType.other]: HttpException: Invalid response line, uri = http://192.168.1.103:2020/onvif/service
E/flutter (11958): #0 DioMixin.assureDioError (package:dio/src/dio_mixin.dart:819:20)
E/flutter (11958): #1 DioMixin._dispatchRequest (package:dio/src/dio_mixin.dart:678:13)
E/flutter (11958):
E/flutter (11958): #2 DioMixin.fetch.. (package:dio/src/dio_mixin.dart)
E/flutter (11958):
E/flutter (11958):
E/flutter (11958): #0 Soap.send (package:easy_onvif/src/soap.dart:34:7)
E/flutter (11958):
E/flutter (11958): #1 Soap.retrieveEnvlope (package:easy_onvif/src/soap.dart:43:26)
E/flutter (11958):
E/flutter (11958): #2 Ptz.continuousMove (package:easy_onvif/src/ptz.dart:30:5)
E/flutter (11958):
E/flutter (11958): #3 Ptz._zoom (package:easy_onvif/src/ptz.dart:192:5)
E/flutter (11958):
E/flutter (11958): #4 Ptz.zoomIn (package:easy_onvif/src/ptz.dart:203:5)

Thanks for your prompt reply on this next.

@wmhseir3
Copy link
Author

just tried the 0.0.11 with this issue and the same DioError appeared.

@wmhseir3
Copy link
Author

please look into the soap messages below which causes the "HttpException: Invalid response line " issue when zoom connect to both of my test devices. this issue stops my further progress
HttpException_Invalid_response_line.txt
.

@faithoflifedev
Copy link
Owner

I've published v0.0.12, which corrected a problem with the Onvif SOAP envelope and also includes a working example for a Flutter app in the example folder.

However, I'm not confident that these changes will resolve the "HttpException: Connection closed" issue. I suspect that this issue may be related to the minimal support that Dart has for XML processing. In the current implementation of easy_onvif I'm using the xml2json package to convert the XML response (a big string) into json, which then gets converted into Dart objects. For very large responses this is very inefficient, and on resource constrained mobile devices, it has the potential to be a problem.

Though, since I can't replicate this issue I can't be certain that this is actually the cause of the "HttpException: Connection closed" error.

My suggestion is to try out both the example flutter app and the sample cli app (available in the github repository) and see if the error still occurs in one or both cases. This could give a clue to the source of the problem.

@wmhseir3
Copy link
Author

I tried 0.12.0 with the flutter_model example. It's still getting the HttpException: Connection closed before full header was received" with the new 2nd nvt. I would like to offer you the steps for you to test with this nvt remotely in your end. Can you please send email to me @wmhseir3@gmail.com?

@faithoflifedev
Copy link
Owner

I don't have a full explanation, but I see a problem with the "Onvif Rtsp Server for Android" even without using my code. I used the following curl command to attempt to get a response from the device and it fails as well:

curl -vvv -XPOST "http://192.168.2.182:8000/onvif/device_service" -H "Content-Type: application/xml" -d'<?xml version="1.0" encoding="UTF-8"?><Envelope xmlns="http://www.w3.org/2003/05/soap-envelope"><Header/><Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetSystemDateAndTime xmlns="http://www.onvif.org/ver10/device/wsdl"/></Body></Envelope>'

The same command works with both test devices I have available.

@faithoflifedev
Copy link
Owner

Also, reading through the Happytimesoft Technology Co. user manual for the Onvif Sever on page 14, I see that the "GetSystemDateAndTime" feature doesn't appear to be supported, so as confirmation that the problem is not command related, I also ran:

curl -vvv -XPOST "http://192.168.2.182:8000/onvif/device_service" -H "Content-Type: application/xml" -d'<?xml version="1.0" encoding="UTF-8"?><Envelope xmlns="http://www.w3.org/2003/05/soap-envelope"><Header/><Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetCapabilities xmlns="http://www.onvif.org/ver10/device/wsdl"><Category>All</Category></GetCapabilities></Body></Envelope>'

which uses "GetCapabilities", which the documentation shows is supported. It gives the same curl: (52) Empty reply from server response as the previous command.

So, I don't think I can do much more to help with this issue.

@faithoflifedev
Copy link
Owner

@wmhseir3 , if you're interested, I was able to find a Onvif server that runs in a docker container. It's really easy to use. Just clone the repository then from the repository folder run:

docker run -p 8080:8080 -it mpromonet/v4l2onvif -uadmin -padmin

Then you can test my sample flutter app using the following config:

host: "10.0.2.2:8080"
username: "admin "
password: "admin"

See this StackOverflow post if you need an explanation for the IP address.

With this setup easy_onvif v0.0.13 works as expected. The more recent version better follows the Onvif spec when responding to a "GetSystemDateAndTime" with a "GetSystemDateAndTimeResponse".

@faithoflifedev
Copy link
Owner

@wmhseir3, I've gone a little overboard on this, since I don't like not knowing :-)

To check if the problem with "Onvif Rtsp Server for Android" was network related I installed the server app and my sample client onto the same device and experienced the same problem.

Next I tried to telnet to the advertised IP address and port for the server app. For this I do get an initial connection, however trying to send any data to the server through this connection, causes the connection to close.

Taking the same steps with the "mpromonet/v4l2onvif" docker container however worked as expected: (the request, sent with telnet)

POST /onvif/device_service HTTP/1.0
Content-Type: application/xml
Content-Length: 334

<?xml version="1.0" encoding="UTF-8"?><Envelope xmlns="http://www.w3.org/2003/05/soap-envelope"><Header/><Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetCapabilities xmlns="http://www.onvif.org/ver10/device/wsdl"><Category>All</Category></GetCapabilities></Body></Envelope>

I got this response:

HTTP/1.1 200 OK
Server: gSOAP/2.8
X-Frame-Options: SAMEORIGIN
Content-Type: application/soap+xml; charset=utf-8
Content-Length: 5171
Connection: close

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope ...

This points fairly conclusively to the problem being related to the "Onvif Rtsp Server for Android" software. It looks like there is an issue with the HTTP server portion of the app. I was able to connect with out issue with both telnet and VLC to the RTSP port of the app. So that part appears to be functioning properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants