Reputation: 265
i was trying to get the C# version of the following java code snippet,
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestProperty("Range", "bytes=1024-");
this is what i have so far
WebRequest request = WebRequest.Create(someUri);
request.Headers.Add("Range", "bytes=1024-");
but it is not working,what is the right way for me go?
Upvotes: 2
Views: 5866
Reputation: 22342
You are setting two different things.
A request property is a value passed to the page.
A header property is a header in the HTTP request. Something like setting the HTTP REFERER (sic).
Upvotes: 0
Reputation: 69372
Presumably your URI is HTTP since Java's HttpURLConnection
is designed for a HTTP connection. WebRequest is abstract and can handle multiple protocols. However, by specifiying a HttpWebRequest
type, you can access HTTP-specific methods.
The Range
header is protected and you should use AddRange to set the property instead of directly adding it to the Header
collection.
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(someUri);
request.AddRange("bytes",1024);
Upvotes: 4