zoukankan      html  css  js  c++  java
  • netcore PostAsync application/x-www-form-urlencoded

    IHttpClientFactory _httpClientFactory;
            public HttpController(IHttpClientFactory httpClientFactory)
            {
                _httpClientFactory = httpClientFactory;
            }
            [HttpGet]
            public async Task<IActionResult> Get3()
            {
                var client = _httpClientFactory.CreateClient();
                var dic = new Dictionary<string, object> { { "scope", "api1" },
                    { "grant_type", "password" },
                    { "client_id","ro.client" },
                    { "client_secret","secret" },
                    { "username","alice"},
                    { "password","password" } };
                var dic_str = dic.Select(m => m.Key + "=" + m.Value).DefaultIfEmpty().Aggregate((m, n) => m + "&" + n);
                HttpContent httpcontent = new StringContent(dic_str);
                httpcontent.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
                var oauth_rep = await client.PostAsync("http://localhost:100/connect/token", httpcontent);
                var oauth_str = await oauth_rep.Content.ReadAsStringAsync();
                var oauth_job = JsonConvert.DeserializeObject<JObject>(oauth_str);
    
    
                client.SetBearerToken(oauth_job["access_token"].ToString());
                var data_rep = await client.GetStringAsync("http://localhost:101/api/values/get");
                var data_job = JsonConvert.DeserializeObject<JObject>(data_rep);
                return Ok(data_job);
            }

    第一部分获取token,第二部分获取数据

  • 相关阅读:
    Docker数据卷
    Hyperloglog算法
    Greenplum6.9集群安装文档
    Java实现线程间通信方式
    计算机存储管理方式
    greenplum6.9踩坑总结
    Linux 内核参数Overcommit_memory(最近生产中Airflow和Greenplum有被这个参数坑到......)
    Airflow概念
    airflow安装文档
    基于Docker进行Zookeeper集群的安装
  • 原文地址:https://www.cnblogs.com/huanyun/p/11636309.html
Copyright © 2011-2022 走看看