首先,我是一个新的http和mjpeg-stream,所以我很可能只有一个理解问题。也许有人可以帮助我。
我从ip camera获取mjpeg流时出了问题。调用流的链接在浏览器中工作正常,我可以观看直播。 (例如http://192.168.xx.xx:8081/cgi-bin/hi3510/mjpegstream.cgi?-chn=11&-usr=user&-pwd=password,其中xx.xx和user,密码是占位符)
如果我尝试将uwp应用程序连接到ip camera,我就不会再回来了。我尝试了这么多解决方案,但没有人仍然适合我。 (这些是一些尝试的解决方案:
我的源代码如下所示:
var newParams = new[]
{
new KeyValuePair<string, string>("-chn", "11")
};
var baseUrl = new Url("http://192.168.xx.xx:8081");
Debug.WriteLine(baseUrl);
using (var fc = new FlurlClient(baseUrl).EnableCookies())
{
// login on page
var loginResponse = await baseUrl
.WithClient(fc)
.PostUrlEncodedAsync(new
{
usr = "user",
pwd = "password"
});
//StatusCode 200
if (loginResponse.IsSuccessStatusCode)
{
try
{
// get mjepg stream from page
var streamResult = await baseUrl
.AppendPathSegments(new string[] { "cgi-bin", "hi3510", "mjpegstream.cgi" })
.SetQueryParams(newParams)
.WithClient(fc)
.GetStreamAsync();
var memNewStream = new MemoryStream();
await streamResult.CopyToAsync(memNewStream);
memNewStream.Position = 0;
mediaElement.SetSource(memNewStream.AsRandomAccessStream(), "multipart/alternative");
}
catch (FlurlHttpException ex)
{
Debug.WriteLine(ex);
}
}
}
我总是:
Flurl.Http.FlurlHttpException:请求http://192.168.xx.xx:8081/cgi-bin/hi3510/mjpegstream.cgi?-chn=11&-usr=user&-pwd=password失败,状态码为401(未授权)var streamResult = await baseUrl .AppendPathSegments(new string[] { "cgi-bin", "hi3510", "mjpegstream.cgi" }) .SetQueryParams(newParams).WithClient(fc).GetStreamAsync();
。
如果我将baseURL更改为var baseUrl = new Url("http://192.168.xx.xx:8081/cgi-bin/hi3510/mjpegstream.cgi?-chn=11&-usr=user&-pwd=password");
并尝试连接,我将获得相同的状态代码401.
提前多多感谢!
更新 在浏览器中调用流的链接htp://192.168.xx.xx:8081 / cgi-bin / hi3510 / mjpegstream.cgi?-chn = 11&amp; -usr = user&amp; -pwd = password。 - &gt; 确定
在上面的Sourcecode示例中第一次调用
var loginResponse = await baseUrl.WithClient(fc).PostUrlEncodedAsync(new { usr = "user", pwd = "password" });
- &gt; 确定 Url http://192.168.xx.xx:8081
在上面的Sourcode示例中,第二次调用
var streamResult = await baseUrl.AppendPathSegments(new string[] { "cgi-bin", "hi3510", "mjpegstream.cgi" }).SetQueryParams(newParams).WithClient(fc).GetStreamAsync();
- &gt; 例外 Flurl.Http.FlurlHttpException: Request to http://192.168.178.35:8081/cgi-bin/hi3510/mjpegstream.cgi?-chn=11 failed with status code 401 (Unauthorized).
Url http://192.168.xx.xx:8081/cgi-bin/hi3510/mjpegstream.cgi?-chn=11
多数民众赞成你想要的东西?
答案 0 :(得分:0)
401(Unathorized)代码说明了一切:您的身份验证存在问题:
问题可能是IP cam无法通过凭据授权您 在URL。
(或)您可能在凭据的其他位置输入错字。
(或)对于不使用浏览器的远程连接,IP cam可能需要使用其他一些身份验证基础。例如。有些浏览器通过HTTP标头发送它。
您是否浏览过IP通信数据表?每次尝试连接时都可能需要进行身份验证,这可能需要在流打开期间发送凭据:
我刚检查过link in comments,他们将凭据示例指定为:
http://IP-Address:Port/tmpfs/snap.jpg?usr=admin&pwd=instar ::快照(720p / 1280x720像素)
请注意“usr”或“pwd”前面没有“ - ”。