HttpClient Portable returns 404 notfound on WP8

一世执手 提交于 2020-01-06 03:17:12

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/16915246/httpclient-portable-returns-404-notfound-on-wp8

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