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

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

httpclient調用WebAPI

2019-11-14 14:31:57
字體:
來源:轉載
供稿:網友

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;


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 赫章县| 定远县| 卓资县| 乐亭县| 南城县| 泸州市| 抚州市| 和顺县| 长兴县| 长顺县| 达孜县| 佛坪县| 温宿县| 无极县| 家居| 天全县| 锦屏县| 岳西县| 将乐县| 卢湾区| 宝兴县| 肇州县| 丰镇市| 邹平县| 祁东县| 肥东县| 江城| 松潘县| 简阳市| 柳州市| 昆明市| 新乡市| 莱州市| 威海市| 隆安县| 富蕴县| 金溪县| 平原县| 六枝特区| 五峰| 辽阳市|