调用 URL - c#

发布于 2024-08-30 21:32:36 字数 159 浏览 2 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

ぃ弥猫深巷。 2024-09-06 21:32:36

您需要实际执行请求:

var request = (HttpWebRequest)WebRequest.Create(url);
request.GetResponse();

对 GetResponse 的调用对服务器进行出站调用。如果您不关心该响应,可以将其丢弃。

You need to actually perform the request:

var request = (HttpWebRequest)WebRequest.Create(url);
request.GetResponse();

The call to GetResponse makes the outbound call to the server. You can discard the response if you don't care about it.

空气里的味道 2024-09-06 21:32:36

首先) 创建WebRequest来执行URL。

第二) 使用WebResponse获取响应。

最后) 使用StreamReader解码响应并将其转换为普通字符串。

string url = "Your request url";
WebRequest request = HttpWebRequest.Create(url);
WebResponse response = request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string responseText = reader.ReadToEnd();

First) Create WebRequest to execute URL.

Second) Use WebResponse to get response.

Finally) Use StreamReader to decode response and convert it to normal string.

string url = "Your request url";
WebRequest request = HttpWebRequest.Create(url);
WebResponse response = request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string responseText = reader.ReadToEnd();
摘星┃星的人 2024-09-06 21:32:36

你可以使用这个:

string address = "http://www.yoursite.com/page.aspx";
using (WebClient client = new WebClient())
{
    client.DownloadString(address);
}

You can use this:

string address = "http://www.yoursite.com/page.aspx";
using (WebClient client = new WebClient())
{
    client.DownloadString(address);
}
时光磨忆 2024-09-06 21:32:36

不,当你说 request.GetResponse(); 时然后你调用它。

No when you say request.GetResponse(); then you invoke it.

青萝楚歌 2024-09-06 21:32:36

可能不会。请参阅: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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文