std::vector<uint8_t> HttpClient::getData(const std::string& url, uint64_t offset, uint64_t size) { std::vector<uint8_t> data; int32_t httpStatus = 0; int contentLength = 0; void* pHandle = nullptr; try { pHandle = open(url, contentLength, httpStatus, offset, size); data.resize(contentLength); read(pHandle, data.data(), contentLength); UpnpCloseHttpGet(pHandle); } catch (std::exception& e) { UpnpCloseHttpGet(pHandle); throw std::logic_error(stringops::format("Failed to read http data from url: %s (%s)", url, e.what()).c_str()); } throwOnBadHttpStatus(url, httpStatus); return data; }
size_t HttpClient::getContentLength(const std::string& url) { int32_t httpStatus = 0; int contentLength = 0; void* pHandle = open(url, contentLength, httpStatus); UpnpCloseHttpGet(pHandle); throwOnBadHttpStatus(url, httpStatus); return contentLength; }
void HttpClient::getData(const std::string& url, uint8_t* pData) { int32_t httpStatus = 0; int contentLength = 0; void* pHandle = nullptr; try { pHandle = open(url, contentLength, httpStatus); read(pHandle, pData, contentLength); UpnpCloseHttpGet(pHandle); } catch (std::exception& e) { UpnpCloseHttpGet(pHandle); throw std::logic_error(stringops::format("Failed to read http data from url: %s (%s)", url, e.what()).c_str()); } throwOnBadHttpStatus(url, httpStatus); }
std::vector<uint8_t> HttpClient::getData(const std::string& url) { std::vector<uint8_t> data; int32_t httpStatus = 0; int contentLength = 0; void* pHandle = open(url, contentLength, httpStatus); data.resize(contentLength); read(pHandle, data.data(), contentLength); UpnpCloseHttpGet(pHandle); throwOnBadHttpStatus(url, httpStatus); return data; }
std::string HttpClient::getText(const std::string& url) { std::string data; int32_t httpStatus = 0; int contentLength = 0; void* pHandle = open(url, contentLength, httpStatus); data.resize(contentLength); read(pHandle, reinterpret_cast<uint8_t*>(&data.front()), contentLength); assert(data[data.size()] == '\0'); UpnpCloseHttpGet(pHandle); throwOnBadHttpStatus(url, httpStatus); return data; }
ERROR_TYPE IUpnp::CloseHttpGet(IN void *handle) { return (ERROR_TYPE)UpnpCloseHttpGet(handle); }