调用 URL - c#
我正在尝试在 C# 中调用 URL,我只对调用感兴趣,并不关心响应。当我出现以下内容时,是否意味着我正在调用该 URL?
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
I m trying to invoke a URL in C#, I am just interested in invoking, and dont care about response. When i have the following, does it mean that I m invoking the URL?
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您需要实际执行请求:
对 GetResponse 的调用对服务器进行出站调用。如果您不关心该响应,可以将其丢弃。
You need to actually perform the request:
The call to GetResponse makes the outbound call to the server. You can discard the response if you don't care about it.
首先) 创建WebRequest来执行URL。
第二) 使用WebResponse获取响应。
最后) 使用StreamReader解码响应并将其转换为普通字符串。
First) Create WebRequest to execute URL.
Second) Use WebResponse to get response.
Finally) Use StreamReader to decode response and convert it to normal string.
你可以使用这个:
You can use this:
不,当你说 request.GetResponse(); 时然后你调用它。
No when you say request.GetResponse(); then you invoke it.
可能不会。请参阅:http://www.codeproject.com/KB/webservices/HttpWebRequest_Response.aspx< /a>
您可以设置 Method、ContentType 等,所有这些都必须在请求实际发送之前完成。看起来 GetResponse() 实际上发送了请求。您可以简单地忽略返回值。
Probably not. See: http://www.codeproject.com/KB/webservices/HttpWebRequest_Response.aspx
You're allowed to set the Method, ContentType, etc., all which would have to be done before the request is actually sent. It looks like GetResponse() actually sends the request. You can simply ignore the return value.