2

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?

3
  • the java code works fine,but not the C# code Commented May 15, 2011 at 18:09
  • 1
    But he's asking what's not working. Commented May 15, 2011 at 18:09
  • 1
    What with the C# code isn't working? Commented May 15, 2011 at 18:12

2 Answers 2

4

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);
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.