Search code examples
windows-phone-8portable-class-librarydotnet-httpclient

HttpClient Portable returns 404 notfound on WP8


I'm porting a W8 application that uses httpclient library to connect to our server.

The main purpose of the application is to send images, but when I try to send pictures on my WP8 I got a 404 not found error (seems that Microsoft remapped to 404 a lot of errors), if i check the server logs, I can see that the server recevied about 1/4 of the image before failling. The same function seems to works fine in my W8 application (didn't tested on 3G), and works on WP8 if I use Wifi connection. I think that the problem could be the waiting time, so I tried to add Keep-Alive headers without success. The current code I have is:

using (HttpClient httpClient = new HttpClient())
{
    httpClient.Timeout = TimeSpan.FromMinutes(10);

    Stream streamW = new MemoryStream();
    this.bSyncOK = await Send(streamW);
    streamW.Seek(0, SeekOrigin.Begin);
    HttpResponseMessage response = await httpClient.PostAsync(sUri, new StreamContent(streamW));

    if (response.IsSuccessStatusCode)
    {
        Stream streamR = await response.Content.ReadAsStreamAsync();
        this.bSyncOK = await Recv(streamR);
        streamR.Dispose();
    }
    else
        throw new HostNotFoundException();
}

The same server is used to upload pictures on other platforms like IOS and Android without problems.


Solution

  • I reproduced the problem using fiddler to simulate modem speeds. The problem is happening because Phone's HTTPWebRequest implementation will timeout the request whenever it exceeds around 60s. In the debugger I see them getting back ERROR_INTERNET_TIMEOUT from their native layer. The only workaround I can think of at the moment would be to send the file in smaller POSTs, assuming the server supports that.