Webclient s downloadstring(url)从Azure函数运行时返回403,但在与Azure-Functions-Core-Tools的本地调试中正常工作
我无法弄清楚为什么我的代码在本地上运行良好,而不是在Azure功能上运行。
段
using (var client = new WebClient ())
{
log.LogInformation($"Fetching html from {url}");
try
{
var response = client.DownloadString(url);
baseHtmlBasePageList.Add(response);
}
catch(Exception ex)
{
log.LogError(ex.Message);
}
}
这是我要点击的url代码 是 https://www.redfin.com/zipcode /20171 。 我试图确定问题可能在哪里..
- Redfin是否能够区分来自Azure与我本地机器的请求并做出不同的反应?
- 我需要明确设置Azure上的某些设置吗?
代码/功能本身非常简单。它的功能像上面提到的示例一样获取URL,通过调用Downloadstring(URL)方法来获取HTML,并从返回的字符串中返回前20个字符。
我确实知道,网络客户已弃用,但是我们可以肯定地说,这就是为什么我本地机器和Azure之间行为不一致的原因?
I am not able to figure out why my code runs fine on my local but doesn't on azure functions.
This is the code snippet
using (var client = new WebClient ())
{
log.LogInformation(quot;Fetching html from {url}");
try
{
var response = client.DownloadString(url);
baseHtmlBasePageList.Add(response);
}
catch(Exception ex)
{
log.LogError(ex.Message);
}
}
The URL I am trying to hit is https://www.redfin.com/zipcode/20171.
I am trying to determine where the issue could be.. like
- Is Redfin able to differentiate between a request coming from Azure vs my local machine and respond differently?
- Is it some setting on Azure that I need to set explicitly?
The code/function itself is very simple. Its a function that takes url like the example mentioned above, fetches the html by calling the DownloadString(url) method and returns the first 20 chars from the returned string.
I do understand that WebClient is deprecated but can we say for certain that that is why the behavior is not consistent between my local machine and Azure?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论