image

.NET7 uses HttpClient to realize query weather forecast interface

.NET7 uses HttpClient to implement query weather forecast interface A friend needs to display the weather forecast according to the city to make a website. After searching around, he couldn’t find a reliable interface. Today, he found an interface in a certain city on the official website of the Central Meteorological Observatory. First, he tried it with postman and it actually worked. You can check it 7-day weather forecast and other information for a certain city. But the query code is the code of the Meteorological Observatory itself. I searched the Internet and found this code. This article uses the HttpClient method to query this interface. Weather interface City Code HttpClient is the most commonly used http request tool on the .net core platform. It is developed directly based on Socket and provides an asynchronous and friendly code writing method. It is under the System.Net.Http namespace. 1. Create a new environment First create a .NET7 Asp.net core web Api program. The options are as follows. Second, create a new GetWeather in the controller Here we use the get method to request, query the weather forecast by passing in the city name, put the city name and code into the Dictionary,…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索