开发者

How do you set up the correct HTTP Response object for a Range request coming from BITS (Background Intelligent Transfer Service)?

开发者 https://www.devze.com 2023-04-07 15:18 出处:网络
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\" st

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.

My code currently receives the http request (with a valid range is present in the http headers of 0 - 4907), and subsequently dish开发者_运维知识库es out a portion of a byte array in the response object.

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.

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.

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

Regards


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

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.

Thanks for the response.


You could also test-run your BITS request(s) against a known static file and sniff the packets with WireShark. That's sure to reveal exactly how to do it.

0

精彩评论

暂无评论...
验证码 换一张
取 消