IXMLHTTPRequest2 upload failure

392 Views Asked by At

I'm creating a WP8 application that uploads pictures to our server.

For that purpose I created a Windows Phone Component for doing all the connection task using IXMLHTTPRequest2. The problem that I have is that when I upload pictures and takes a little bit longer than expected, I get in the OnError function the following error: INET_E_DOWNLOAD_FAILURE (0x800C0008L) Studing the problem, seems that the phone stops sending data, but sometimes after a long time (maybe 1 min) it continue and send some bytes more (not all the remaining) so the problem is that almost every time, the communication got interrupted, even if the server is still waiting for the information. If i connect using WiFi there is no problem because it doesn't take too much time on sending the picture.

Does any one had a similar problem and what can I do to fix this issue?

The code (summarized) is:

ComPtr<IXMLHTTPRequest2>                _httpRequest = NULL;
ComPtr<IXMLHTTPRequest2Callback>    _xhrCallback = NULL;
ComPtr<html_internal>                _mhtmlInternal = NULL;
cancellation_token_source                _cancellationTokenSource;

hResultXHR = CoCreateInstance(CLSID_XmlHttpRequest, nullptr, CLSCTX_INPROC, IID_PPV_ARGS(&_httpRequest));
dwError = getURI(&pwcURI, this->_host->Data(), this->_cgiPath->Data(), this->_port, this->_secure);
_cancellationTokenSource = cancellation_token_source();
_mhtmlInternal = Make<html_internal>(_httpRequest.Get(), _cancellationTokenSource.get_token(), nullptr);
if (hResultXHR == S_OK)
    hResultXHR = _mhtmlInternal.As(&_xhrCallback);
if (hResultXHR == S_OK)
    hResultXHR = _httpRequest->Open(L"Post", //Método a utilizar
        pwcURI,
        _xhrCallback.Get(),
        nullptr,
        nullptr,
        nullptr,
        nullptr);
if (hResultXHR == S_OK)
    hResultXHR = _httpRequest->SetProperty(XHR_PROP_TIMEOUT, _timeReadOut);
if (hResultXHR == S_OK)
    hResultXHR = _httpRequest->SetRequestHeader(L"Content-Type", L"text/plain;charset=utf-8");
if (hResultXHR == S_OK)
    hResultXHR = CreateStreamOnHGlobal(NULL, TRUE, &_pISendStream);
if (hResultXHR == S_OK)
    hResultXHR = CreateStreamOnHGlobal(NULL, TRUE, &_pIRecvStream);
if (hResultXHR == S_OK)
{
    if (_pISendStream != NULL)
        hResultXHR = _httpRequest->Send(_pISendStream, p->ulSize);
    else
        hResultXHR = _httpRequest->Send(nullptr, 0);
}
return create_async([this, _mhtmlInternal, hResultXHR]() -> int
{
    _mhtmlInternal->CreateDataTask();
    _mhtmlInternal->CreateDataTask().wait();
    _statusCode = 0;
    HRESULT hResultXHR = _mhtmlInternal->GetError();
    if (hResultXHR == S_OK)
    {
        _statusCode = _mhtmlInternal->GetStatusCode();
        auto reasonPhrase = _mhtmlInternal->GetReasonPhrase();
        if (_statusCode == 200)
        {
            //Do stuff
        }
    }
    if (this->_pIRecvStream != NULL)
    {
        this->_pIRecvStream->Release();
        this->_pIRecvStream = NULL;
    }
    if (this->_pISendStream != NULL)
    {
        this->_pISendStream->Release();
        this->_pISendStream = NULL;
    }
    return (this->dwError);
});
0

There are 0 best solutions below