该流不支持查找操作。 HttpWebResponse [英] This stream does not support seek operations. HttpWebResponse

查看:3762
本文介绍了该流不支持查找操作。 HttpWebResponse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个程序,它会下载通过HTTP文件。

I'm making a program which downloads files over http.

我找到了下载,但是我希望能够暂停下载,关闭计划在以后再次恢复它们。

I've got it downloading, however I want to be able to pause the downloads, close the program and resume them again at a later date.

我知道我是从支持下载他们的位置这一点。

I know the location i'm downloading them from supports this.

我下载该文件通过HttpWebResponse和读取使用GetResponseStream响应到流。

I'm downloading the file through HttpWebResponse and reading the response into a Stream using GetResponseStream.

当我关闭该应用程序并重新启动它,我卡作为如何恢复下载。我试着做一个寻求流,但它指出其不支持。

When i close the app and restart it, I'm stuck as to how resume the download. I've tried doing a seek on the stream but it states its not supported.

什么是做到这一点的最好方法是什么?

What would be the best way to do this?

推荐答案

如果服务器支持这一点,你需要发送的使用的 HTTP头您的要求=http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest .addrange.aspx相对=nofollow>的AddRange 方式:

If the server supports this you have to send the Range Http header with your request using the AddRange method:

request.AddRange(1024);

这将指示服务器开始第一千字节后发送文件。然后,只需读取响应流是正常的。

This will instruct the server to start sending the file after the 1st kilobyte. Then just read the response stream as normal.

要测试一个服务器支持恢复您可以发送 HEAD 要求并测试它发送接受-范围:字节

To test if a server supports resuming you can send a HEAD request and test if it sends the Accept-Ranges: bytes header.

这篇关于该流不支持查找操作。 HttpWebResponse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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