我正在VS15測試版中嘗試使用WebClient。雖然System.Net被引用,而智能感知意味着WebClient類是可用的,在構建我得到以下錯誤:在ASP.NET 5中使用WebClient
The type or namespace name 'WebClient' does not exist in the namespace 'System.Net' (are you missing an assembly reference?) MyProj.ASP.NET Core 5.0 HomeController.cs
我做以下簡單的代碼:
var client = new System.Net.
var html = client.DownloadString(url);
當我去到Web客戶端的定義,它顯示了我的來源。不太清楚問題是什麼 - WebClient移動了嗎?我正在努力尋找決議。
謝謝!
可能會建議將使用'(...){...}'爲HttpClient的例子,所以讀者不要忘了妥善處置。 –
HttpClient不需要根據創建者進行處理。他們建議您重複使用HttpClient,而不是每次創建一個請求。 –
要添加對project.json的引用,只需使用「dnu install System.Net.Http」 –