gpt4 book ai didi

xml - 来自 weather.gov 的当前观察提要被禁止 (403)

转载 作者:数据小太阳 更新时间:2023-10-29 01:42:41 24 4
gpt4 key购买 nike

对于来自 HTTPClient 的所有请求,Weather.gov Current Observation 提要突然开始失败,同样我观察到互联网上许多使用 AJAX 调用 weather.gov 的网站也失败了。

所有调用 weather.gov 当前观测提要的结果,例如http://w1.weather.gov/xml/current_obs/TAPA.xml ,返回 403。所述 URL 在浏览器中正确解析。

最佳答案

联系 weather.gov 得到了非常快速的响应,即:

Applications accessing resources on weather.gov now need to provide a User-Agent header in any HTTP request. Requests without a user agent are automatically blocked. We have implemented this usage policy due to a small number of clients utilizing resources far in excess of what most would consider reasonable.

We recommend providing a user agent string in the following format:

ApplicationName/vX.Y (http://your.app.url/; contact.email@example.com)

This will both uniquely identify your application and allow us to contact you and work with you if we observe abnormal application behavior that may result in a block.

Please feel free to email us back if you continue to have issues after verifying that your application is sending the proper headers.

Thanks for using weather.gov.

=======

这是一段 C# 代码。关键是您需要创建请求对象,然后在调用之前向其附加自定义用户代理字符串。

...
var request = new HttpRequestMessage(HttpMethod.Post, httpClient.BaseAddress.AbsoluteUri);
request.Headers.Add("User-Agent", "MyApplication/v1.0 (http://foo.bar.baz; foo@bar.baz)");
var httpResponse = httpClient.SendAsync(request).Result;
...

希望对大家有所帮助。干杯

关于xml - 来自 weather.gov 的当前观察提要被禁止 (403),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32641072/

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