gpt4 book ai didi

c# - 检查 ASP.NET 中是否存在文本文件

转载 作者:行者123 更新时间:2023-11-30 12:36:59 24 4
gpt4 key购买 nike

我需要检查文本文件是否存在于不同域的站点上。网址可以是:

http://sub.somedomain.com/blah/atextfile.txt

我需要从后台代码执行此操作。我正在尝试使用 HttpWebRequest 对象,但不确定如何使用。

编辑:我正在寻找一种轻量级的方法来执行此操作,因为我将每隔几秒执行一次此逻辑

最佳答案

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(
"http://sub.somedomain.com/blah/atextfile.txt");

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

if (response.StatusCode == HttpStatusCode.OK)
{
// FILE EXISTS!
}
response.Close();

关于c# - 检查 ASP.NET 中是否存在文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2211177/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com