ReadAsStringAsync及其导入

时间:2019-03-03 07:31:33

标签: .net vb.net

我有两个项目,都是.NET Framework 4.7.2。

在两个项目中,我的Imports语句都是相同的。

Imports System.IO
Imports System.Net
Imports System.Security.Cryptography
Imports System.Text
Imports System.Net.NetworkInformation
Imports System.Net.Http

较旧的项目可以识别HttpClient,但是较新的项目则不能...

Public Async Function getQueryURL(url As String) As Threading.Tasks.Task
  Dim hc As HttpClient
  hc = New HttpClient
  Dim strServerInfo As String = ""
  Dim result As String = ""

  Dim rm As HttpResponseMessage()
  rm = Await hc.GetAsync(url)

  If rm.IsSuccessStatusCode Then
    Dim res As String
    res = Await rm.Content.ReadAsStringAsync()

    result = res
  End If
End Function

破碎的项目想导入(快速refaktor)

Imports Windows.Web.Http

1 个答案:

答案 0 :(得分:-2)

禁止进口

Imports Windows.Web.Http

我必须在项目中引用System.Net.Http的路径

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Net.Http.dll then it works... it does not work automatically 

然后该项目使用正确的扩展版本von Windows.Web.Http

Imports Windows.Net.Http