help to convert java code to C#
i was trying to get the C# version of the following java code snippet,
HttpURLConnection connection = (HttpURLConnect开发者_高级运维ion)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?
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);
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).
精彩评论