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.
问问题
3250 次
1 回答
2
我会说按照@StevenV 所说的去做,并尝试在 URI 中编码凭据。
如果这不起作用或者您不想使用该方法,则必须改用 POCO HTTPClientSession 类。像这样的东西:
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;
}
于 2013-10-15T14:56:56.230 回答