Load image from URL in C++

。_饼干妹妹 提交于 2019-12-06 05:13:10

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

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;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!