【发布时间】:2017-11-01 15:38:31
【问题描述】:
我正在尝试使用我的 Web API 核心服务,该服务托管在我的本地计算机上的 IIS 10 中浏览器地址。
这是我的控制器代码
public IActionResult Index()
{
using (var client = new HttpClient())
{
//Construct API URI
client.BaseAddress = new Uri("http://localhost");
var contentType = new MediaTypeWithQualityHeaderValue("application/json");
client.DefaultRequestHeaders.Accept.Add(contentType);
var response = client.GetAsync("/api/DeviceType/devgetall").Result;
var stringData = response.Content.ReadAsStringAsync().Result;
var data = JsonConvert.DeserializeObject<List<DeviceType>>(stringData);
var deviceTypes = _mapper.Map<List<DeviceTypeModel>>(data);
var modelList = new DeviceTypeModelList {DeviceTypeModels = deviceTypes};
return View(modelList);
}
}
【问题讨论】:
-
能否请您分享一下您是如何使用它的?
-
对不起,我没听懂。
-
我正在尝试通过我的问题中附加的代码来使用它。
-
我的意思是你的调用应该命中的代码。
-
在这些情况下,很多时候问题与动词(GET、POST、...)或请求的参数有关。
标签: asp.net-mvc iis asp.net-web-api hosting .net-core