你如何设置一个范围请求,从BITS(后台智能传输服务)来正确的HTTP Response对象? [英] How do you set up the correct HTTP Response object for a Range request coming from BITS (Background Intelligent Transfer Service)?

查看:165
本文介绍了你如何设置一个范围请求,从BITS(后台智能传输服务)来正确的HTTP Response对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要实现一个Web服务,它可以发出文件到比特(后台智能传输服务)的要求。语言是ASP.NET(C#)。我遇到的问题是与范围的东西。

I have a requirement to implement a web-service that can issue files to the bits (Background Intelligent Transfer Service). The language is ASP.NET (C#). The problem I am having is with the "range" stuff.

我的code当前接受HTTP请求(凭有效范围present在0 HTTP头 - 4907),随后出来的菜肴响应对象的字节数组的一部分。

My code currently receives the http request (with a valid range is present in the http headers of 0 - 4907), and subsequently dishes out a portion of a byte array in the response object.

下面是我的服务器code:

Here's my server code:

_context.Response.Clear();
_context.Response.AddHeader("Content-Range", "bytes " + lower.ToString() + "-" +  upper.ToString() + "//" + view.Content.Length.ToString());
_context.Response.AddHeader("Content-Length", upper.ToString());
_context.Response.AddHeader("Accept-Ranges", "bytes");
_context.Response.ContentType = "application/octet-stream";
_context.Response.BinaryWrite(data);
_context.Response.End();

接下来发生的事情是,随后的请求没有在头的范围键,在所有...就好像它是要求整个文件!不用说,位作业错误,说明服务器响应无效。

What happens next is that the subsequent request does not have any "range" key in the header at all... it's like it is asking for the entire file! Needless to say, the bits job errors stating that the servers response was not valid.

我怀疑,这一切都下降到该服务器在响应对象返回头......我pretty确保我在这里下的协议。

I suspect that it's all down to the headers that the server is returning in the response object... I am pretty sure that I am following protocol here.

如果任何人都可以在这方面帮助这将是极大的AP preciated ...的意思,而...我会继续寻找!

If anyone can help with this it would be greatly appreciated... mean while... I'll keep on searching!

问候

推荐答案

是的,我发现我不得不在总的几个问题。 IIS是一个最初的问题,然后我的长度计算...然后像你​​说的,范围请求它的自我。忽略后者,我最后code该项业务是:

Yes, I found that I had a few issues in total. IIS was an initial problem, then my length calculations... and then like you say, the range request it's self. Ignoring the latter, my final code for this segment was:

_context.Response.StatusCode = 206;
_context.Response.AddHeader("Content-Range", string.Format("bytes {0}-{1}/{2}", lower.ToString(), upper.ToString(), view.Content.Length.ToString()));
_context.Response.AddHeader("Content-Length", length.ToString());
_context.Response.AddHeader("Accept-Ranges", "bytes");
_context.Response.OutputStream.Write(view.Content.ToArray(), lower, length);

处理多请求范围可以不同的一天解决! BITS应该以这种方式要求(就像它在它要求整个文件的第一个请求后的第二个要求),我的code根本没有返回值...然后BITS发送的单个范围的请求......事情的工作确定从那里。

Handling multi-request ranges can be tackled a different day! Should BITS request in this way (like it does on the second request after the first request which asks for the entire file), my code simply returns nothing... and then BITS sends a single range in the request... things work ok from there.

感谢您的答复。

这篇关于你如何设置一个范围请求,从BITS(后台智能传输服务)来正确的HTTP Response对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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