gpt4 book ai didi

flutter - 如何在Flutter中从IP摄像机下载图像

转载 作者:行者123 更新时间:2023-12-03 03:58:09 25 4
gpt4 key购买 nike

当我将HTTP请求发送到IP摄像机(Onvif)时

    "<GetSnapshotUri xmlns=\"http://www.onvif.org/ver20/media/wsdl\">" +
"<ProfileToken>PROFILE_000</ProfileToken></GetSnapshotUri>";


我收到包含网址的响应:

....
<s:Body><trt:GetSnapshotUriResponse><trt:MediaUri>
<tt:Uri>http://192.168.1.102:13237/snapshot.cgi</tt:Uri>
<tt:InvalidAfterConnect>false</tt:InvalidAfterConnect>
<tt:InvalidAfterReboot>false</tt:InvalidAfterReboot><tt:Timeout>PT5S</tt:Timeout></trt:MediaUri>
</trt:GetSnapshotUriResponse></s:Body></s:Envelope>


我尝试使用 image_downloader插件,但无法正常工作。
我可以在浏览器(Chrome)中看到它,但无法通过Image.network(' http://192.168.1.102:13237/snapshot.cgi')小部件查看它

我有错误

════════ Exception caught by image resource service ════════════════════════════════════════════════
The following NetworkImageLoadException was thrown resolving an image codec:
HTTP request failed, statusCode: 401, http://192.168.1.102:13237/snapshot.cgi

When the exception was thrown, this was the stack:
#0 NetworkImage._loadAsync (package:flutter/src/painting/_network_image_io.dart:90:9)
<asynchronous suspension>
#1 NetworkImage.load (package:flutter/src/painting/_network_image_io.dart:47:14)
#2 ImageProvider.resolve.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:327:17)
#3 ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:160:22)
...
Image provider: NetworkImage("http://192.168.1.102:13237/snapshot.cgi", scale: 1.0)
Image key: NetworkImage("http://192.168.1.102:13237/snapshot.cgi", scale: 1.0)
════════════════════════════════════════════════════════════════════════════════════════════════════


我在Java上找到了答案

URL url = new URL("http://webacm-ip-adr:8084/snapshot.cgi");
InputStream input = url.openStream();
String jpg = "sample.jpg";
FileOutputStream output = new FileOutputStream(jpg);
IOUtils.copy(input, output);


得到正确答案后进行更新。我可以看到创建Digest键所需的参数,但是由于无法通过dart代码返回Response对象
Response header in http sniffer that I can't get by Dart code

最佳答案

如何代替图片下载器使用

import 'package:http/http.dart' as http;
import 'dart:io';
import 'package:path_provider/path_provider.dart';
import 'package:flutter/foundation.dart';
Future<File> _downloadFile(String authEncoded,String url, String param) async {
final response = await http.post(url,
headers: {
HttpHeaders.authorizationHeader: 'Basic ' + authEncoded
// Do same with your authentication requirement
},
body: param,
);

response.headers.forEach((k,v) => print (k+" : "+v));
//Your response headers here

if(response.statusCode==200){
String dir = (await getApplicationDocumentsDirectory()).path;
File file = new File('$dir/image.jpg');
await file.writeAsBytes(response.bodyBytes);
return file;
} else {
print("Error : " + response.statusCode.toString());
}
}

现在打电话
File file = await _downloadFile("http://192.168.1.102:13237/snapshot.cgi", "<GetSnapshotUri xmlns=\"http://www.onvif.org/ver20/media/wsdl\"><ProfileToken>PROFILE_000</ProfileToken></GetSnapshotUri>");

关于flutter - 如何在Flutter中从IP摄像机下载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59483029/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com