WebRequest and Range Header

  • Thread starter Thread starter Steve b.
  • Start date Start date
S

Steve b.

Hi,

I'm building an application that can download resources using HTTP.

In order to enable resuming broken download, I'd like to send to the server
some Http Headers :

string uriString = "http://server/app/resource.ext";

WebRequest req = WebRequest.Create(

uriString

);

req.Headers[HttpRequestHeader.IfRange] = ETag;

req.Headers["Range"] = "1254-";



This code is supposed to resume the download after the 1254th byte.

This code throw an exception when setting the Range header. After some
investigations I found the Range headers is blocked within the .Net
framework.



Firstly, why this header is blocked by the system ?

Then, how can I fix this header ?



Thanks in advance

Steve
 
Thus wrote Steve B.,
Hi,

I'm building an application that can download resources using HTTP.

In order to enable resuming broken download, I'd like to send to the
server some Http Headers :

string uriString = "http://server/app/resource.ext";

WebRequest req = WebRequest.Create(

uriString

);

req.Headers[HttpRequestHeader.IfRange] = ETag;

req.Headers["Range"] = "1254-";

This code is supposed to resume the download after the 1254th byte.

This code throw an exception when setting the Range header. After some
investigations I found the Range headers is blocked within the .Net
framework.

Firstly, why this header is blocked by the system ?

There are a number of HTTP headers that are either set through properties
or methods. Setting one of these headers through the Headers collection isn't
allowed.
Then, how can I fix this header ?

Use one of the HttpWebRequest.AddRange() overloads.

Cheers,
 
I've already tryed all possible code for setting the header.
All of methods use the internal Set method in which the check is applied...

Thanks,
Steve

Joerg Jooss said:
Thus wrote Steve B.,
Hi,

I'm building an application that can download resources using HTTP.

In order to enable resuming broken download, I'd like to send to the
server some Http Headers :

string uriString = "http://server/app/resource.ext";

WebRequest req = WebRequest.Create(

uriString

);

req.Headers[HttpRequestHeader.IfRange] = ETag;

req.Headers["Range"] = "1254-";

This code is supposed to resume the download after the 1254th byte.

This code throw an exception when setting the Range header. After some
investigations I found the Range headers is blocked within the .Net
framework.

Firstly, why this header is blocked by the system ?

There are a number of HTTP headers that are either set through properties
or methods. Setting one of these headers through the Headers collection
isn't allowed.
Then, how can I fix this header ?

Use one of the HttpWebRequest.AddRange() overloads.
Cheers,
 
Still no answer ? :(

Steve b. said:
I've already tryed all possible code for setting the header.
All of methods use the internal Set method in which the check is
applied...

Thanks,
Steve

Joerg Jooss said:
Thus wrote Steve B.,
Hi,

I'm building an application that can download resources using HTTP.

In order to enable resuming broken download, I'd like to send to the
server some Http Headers :

string uriString = "http://server/app/resource.ext";

WebRequest req = WebRequest.Create(

uriString

);

req.Headers[HttpRequestHeader.IfRange] = ETag;

req.Headers["Range"] = "1254-";

This code is supposed to resume the download after the 1254th byte.

This code throw an exception when setting the Range header. After some
investigations I found the Range headers is blocked within the .Net
framework.

Firstly, why this header is blocked by the system ?

There are a number of HTTP headers that are either set through properties
or methods. Setting one of these headers through the Headers collection
isn't allowed.
Then, how can I fix this header ?

Use one of the HttpWebRequest.AddRange() overloads.
Cheers,
 
Thus wrote Steve B.,
Still no answer ? :(

Now I'm confused... what about "Use one of the HttpWebRequest.AddRange()
overloads". Doesn't that work for you?

Cheers,
 
Sorry, I've not well understand your answer.

Since I was working on a WebRequest and not on a HttpWebRequest I did not
see the .AddRange method.
I thought you talk about the req.Headers.AddRange (which does not exists
:) )

Thanks a lot, I'll try this method.

But what about downloads that are not Http ?

Thanks,
Steve
 
Thus wrote Steve B.,
Sorry, I've not well understand your answer.

Since I was working on a WebRequest and not on a HttpWebRequest I did
not
see the .AddRange method.
I thought you talk about the req.Headers.AddRange (which does not
exists
:) )
Thanks a lot, I'll try this method.

But what about downloads that are not Http ?

Sorry, I missed the pure WebRequest part and implied HTTP by default.

Range requests are a HTTP feature. I don't know if there's a similar feature
in FTP.

Cheers,
 
Back
Top