HttpClient Portable返回WP8上找不到的404 [英] HttpClient Portable returns 404 notfound on WP8

查看:95
本文介绍了HttpClient Portable返回WP8上找不到的404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在移植一个使用httpclient库连接到我们的服务器的W8应用程序.

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

该应用程序的主要目的是发送图像,但是当我尝试在WP8上发送图片时,出现404 not found错误(似乎Microsoft重新映射为404错误很多),如果我检查服务器日志的话,我可以看到服务器在出现故障之前已删除了大约1/4的图像.相同的功能似乎在我的W8应用程序中正常工作(未在3G上进行测试),并且如果我使用Wifi连接,则在WP8中工作.我认为问题可能是等待时间,因此我尝试添加Keep-Alive标头失败. 我当前拥有的代码是:

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();
}

同一台服务器用于在IOS和Android等其他平台上上传图片而不会出现问题.

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

推荐答案

我重现了使用提琴手模拟调制解调器速度的问题.发生此问题是因为Phone的HTTPWebRequest实现将在超过60s时使请求超时.在调试器中,我看到他们从其本机层取回ERROR_INTERNET_TIMEOUT.我目前唯一能想到的解决方法是在服务器支持的情况下,以较小的POST发送文件.

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.

这篇关于HttpClient Portable返回WP8上找不到的404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆