【发布时间】:2016-01-14 00:14:50
【问题描述】:
我正在尝试按照复数视频中的示例进行操作
当我尝试完成 Api 添加坐标时出现错误:
命名空间“System.Net”中不存在类型或命名空间名称“Http”(您是否缺少程序集引用?)
这发生在以下课程中:
using Microsoft.Extensions.Logging;
using System.Net;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using System.Net.Http;
namespace Moran.Services
{
public class CoordService
{
private ILogger<CoordService> _logger;
public CoordService(ILogger<CoordService> logger)
{
_logger = logger;
}
public async Task<CoordServiceResult> Lookup(string location)
{
var result = new CoordServiceResult()
{
Success = false,
Message = "Undetermined failures while looking up coordinates"
};
//Lookup Coordinates
var bingKey = Startup.Configuration["AppSettings:BingKey"];
var encodedName = WebUtility.UrlEncode(location);
var url = $"http://dev.virtualearth.net/REST/v1/Locations?q={encodedName}&key={bingKey}";
var client = new HttpClient();
var json = await client.GetStringAsync(url);
// Read out the results
// Fragile, might need to change if the Bing API changes
var results = JObject.Parse(json);
var resources = results["resourceSets"][0]["resources"];
if (!resources.HasValues)
{
result.Message = $"Could not find '{location}' as a location";
}
else
{
var confidence = (string)resources[0]["confidence"];
if (confidence != "High")
{
result.Message = $"Could not find a confident match for '{location}' as a location";
}
else
{
var coords = resources[0]["geocodePoints"][0]["coordinates"];
result.Latitude = (double)coords[0];
result.Longitude = (double)coords[1];
result.Success = true;
result.Message = "Success";
}
}
return result;
}
}
}
当我尝试添加时发生这种情况
var client = new HttpClient();
知道为什么会这样吗?
我找不到任何无法编译的原因......
【问题讨论】:
标签: asp.net-core-mvc