Esempio n. 1
0
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;
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
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);
}
Esempio n. 4
0
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;
}
Esempio n. 5
0
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;
}
Esempio n. 6
0
ERROR_TYPE IUpnp::CloseHttpGet(IN void *handle)
{
    return (ERROR_TYPE)UpnpCloseHttpGet(handle);
}