国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

httpclient調用WebAPI

2019-11-14 14:22:12
字體:
來源:轉載
供稿:網友

1、創建webapi項目,提供接口方法如下:

/// <summary>
/// 獲取租戶、位置下的所有傳感器
/// </summary>
/// <returns></returns>
[AcceptVerbs("POST")]
[Route("api/Sensors/GetSensors")]
public JsonResponseBase<List<TenSensorDTO>> GetSensors()
{
Logger.Debug("SensorsController---------------GetSensors");
string jsonData = this.Request.Content.ReadAsStringAsync().Result;
Logger.Information(jsonData);
TenSensorSearchDTO search = null;
var response = new JsonResponseBase<List<TenSensorDTO>>();
try
{
search = JsonConvert.DeserializeObject<TenSensorSearchDTO>(jsonData);
response.Json.IsSuccess = true;
}
catch(Exception ex)
{
Logger.Fatal(ex);
response.Json.IsSuccess = false;
response.Json.OperationDesc = "參數錯誤";
}
if (response.Json.IsSuccess && search != null)
{
response = TenantManageService.GetSensorList(search);
}

return response;
}

2、客戶端使用httpclient調用

string url = urlPRe + "Sensors/GetSensors";
//租戶ID必須傳入,LocationID可以不傳入,看調用段需求
var content = new { TenantID = Guid.Parse("5ebf5f81-ac69-418c-b170-9eb255201dd1") ,
LocationID = Guid.Parse("db5a58c0-1d12-4fe9-99bb-4bebe6bcb935") };
var requestJson = JsonConvert.SerializeObject(content);
HttpContent httpContent = new StringContent(requestJson);
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var httpClient = new HttpClient();
var responseJson = httpClient.PostAsync(url, httpContent)
.Result.Content.ReadAsStringAsync().Result;


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 开远市| 镇康县| 西青区| 丽水市| 临猗县| 肃宁县| 香河县| 襄汾县| 阜康市| 太谷县| 射洪县| 商城县| 东辽县| 柞水县| 盈江县| 徐州市| 昌都县| 容城县| 万载县| 秦皇岛市| 沂水县| 行唐县| 克山县| 东山县| 乌恰县| 高雄市| 漯河市| 仙居县| 西宁市| 香格里拉县| 平塘县| 信丰县| 平泉县| 遂平县| 咸阳市| 图片| 宁晋县| 扎鲁特旗| 军事| 滦南县| 临汾市|