本文介绍了从C ++中的URL加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C ++和OpenCV,我想从受密码保护的URL加载图像。
我成功从URL加载图片使用这个,它使用POCO库,但我不知道当我必须使用用户名和密码才能访问该URL。

I am using C++ and OpenCV and I'd like to load an image from password protected URL.I succeeded in loading image from URL using idea of this link which uses POCO library, but I do not know what should I do when I have to use username and password in order to access the URL.

推荐答案

我会说什么@StevenV说,并尝试编码的凭证在URI中。

I'd say do what @StevenV said and try to encode the credentials in the URI.

不工作,或者您不想使用该方法,则必须使用POCO HTTPClientSession类。像这样:

If that doesn't work or you don't want to use that method you have to use the POCO HTTPClientSession class instead. Something like this:

URI uri(url);
HTTPClientSession session(uri.getHost(), uri.getPort());
HTTPRequest req(HTTPRequest::HTTP_GET, uri.getPathEtc(), HTTPMessage::HTTP_1_1);
HTTPBasicCredentials creds("username","password");
creds.authenticate(req);
session.sendRequest(req);
HttpResponse resp;
std::istream file = session.reveiveResponse(resp);
if(resp.getStatus() == HTTP_OK){
  //copy image from istream file here;
}

这篇关于从C ++中的URL加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 05:20