HttpClient _httpClient;
HttpClient _businessHttpClient; private async Task<string> GetAccessToken()
{
_businessHttpClient = new HttpClient();
_businessHttpClient.BaseAddress = new Uri("http://localhost:8998/Meet.WebApi/");
_httpClient = new HttpClient();
_httpClient.BaseAddress = new Uri("http://localhost:8998/HRManage.WebApi/api/UserLogin?username=admin&password=111111");
var parameters = new Dictionary<string, string>();
parameters.Add("username", "admin");
parameters.Add("password", "");
var response = await _httpClient.PostAsync(_httpClient.BaseAddress, new FormUrlEncodedContent(parameters));
var responseValue = await response.Content.ReadAsStringAsync(); if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
var data = JsonConvert.DeserializeObject<ResultEntity<UserLoginResultDTO>>(responseValue);
return data.Data.AccessToken;
}
else
{
return string.Empty;
}
} [TestMethod]
public void GetMeetingById()
{
string tokenstring = GetAccessToken().Result; _businessHttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenstring);
var response = _businessHttpClient.GetAsync("Meet/GetMeetingById?Id=5C0062FF-542A-4C6E-BE28-5998EC3CEDE4").Result;
var responseValue = response.Content.ReadAsStringAsync().Result;
_businessHttpClient.Dispose();
var data = JsonConvert.DeserializeObject<ResultEntity<MeetingOutDto>>(responseValue);
Assert.AreEqual(true, JObject.Parse(responseValue)["IsSuccess"].Value<bool>(), JObject.Parse(responseValue)["Msg"].Value<string>());
}

Post方式:

        HttpClient _httpClient;
//模拟登陆
public async Task<bool> Login()
{
_httpClient = new HttpClient();
_httpClient.BaseAddress = new Uri("http://localhost:8088");//14199 //
LoginInput log = new LoginInput() { mobile = "", pwd = "" }; HttpContent httpcontent = new StringContent(JsonConvert.SerializeObject(log));
httpcontent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var response = await _httpClient.PostAsync("hcApi/Login/login", httpcontent);
var responseValue = await response.Content.ReadAsStringAsync(); if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
return JObject.Parse(responseValue)["isOK"].Value<bool>();
}
else
{
return false;
}
}
/// <summary>
/// 根据条件获取卫生院信息
/// </summary>
/// <returns></returns>
[TestMethod]
public async Task GetHealthCenterInfo()
{
await Login(); var response = await _httpClient.GetAsync("hcApi/SampleEntry/GetHealthCenterInfo?hcID=57&&keyWord=&&pageIndex=1&&pageSize=10");
var responseValue = await response.Content.ReadAsStringAsync();
_httpClient.Dispose();
Assert.AreEqual(, JObject.Parse(responseValue)["errorCode"].Value<int>(), JObject.Parse(responseValue)["msg"].Value<string>());
}

最新文章

  1. Windbg Extension NetExt 使用指南 【1】 ---- NetExt 介绍
  2. DayuCMS 1.525 /include/global.func.php Foreground Arbitrary Code Execution
  3. Shell获取上一个月、星期的时间范围
  4. jQuery插件开发教程
  5. 操刀 requirejs,自己动手写一个
  6. 网页元素定位神器之Xpath详解
  7. AR增强现实 Augmented Reality
  8. centos6.4上安装phpmyfaq
  9. Robotium自动化测试报告生成
  10. uva 296 - Safebreaker
  11. NumPy简明教程
  12. BitMap画图
  13. 【SEO】搜索引擎优化的陷阱和作弊
  14. hdu_5963:朋友
  15. Grails笔记一:windows8.1操作系统cmd下grails命令无效
  16. 【源码】otter工程结构
  17. react+umi+dva+antd中dva的数据流图解
  18. RabbitMQ系列(六)你不知道的RabbitMQ集群架构全解
  19. shell 日前 之check 年月日
  20. ABP模块运行解析

热门文章

  1. Centos7下安装redis实战(单机版以及集群)
  2. 【JAVA】序列化
  3. docker网络之bridge
  4. Searching with Deep Learning 深度学习的搜索应用
  5. 价值 1500 美元的 iPhone 值得买吗
  6. C++类型转化小结
  7. 【IT笔试面试题整理】数组中出现次数超过一半的数字
  8. 动态绑定数据至Html Table
  9. t3用户-角色-权限hibernate经典配置
  10. c# List&lt; int&gt;和List&lt; string&gt;互相转换