帮助将java代码转换为C#
我试图获取以下 java 代码片段的 C# 版本,
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestProperty("Range", "bytes=1024-");
这是我到目前为止所拥有的
WebRequest request = WebRequest.Create(someUri);
request.Headers.Add("Range", "bytes=1024-");
,但它不起作用,对我来说正确的方法是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您的 URI 是 HTTP,因为 Java 的
HttpURLConnection
是为 HTTP 连接设计的。 WebRequest 是抽象的,可以处理多种协议。但是,通过指定HttpWebRequest
类型,您可以访问特定于 HTTP 的方法。Range
标头受保护< /a> 并且您应该使用 AddRange 来设置属性而不是直接将其添加到Header
集合中。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 aHttpWebRequest
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 theHeader
collection.您正在设置两个不同的东西。
请求属性是传递给页。
标头属性是 HTTP 中的标头要求。比如设置 HTTP REFERER(原文如此)。
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).