protected override void ConfigureClient(HttpClient client)
        {
            base.ConfigureClient(client);
            if (false && client.DefaultRequestHeaders.Authorization == null)
            {
                if (_token == null)
                {
                    var nswagClient = new MyNamespace.Client(client.BaseAddress.ToString(), client);

                    // Act
                    var response = nswagClient.LoginAsync(new MyNamespace.LoginModel {
                        UserName = "******", Password = "******",
                    }).Result;
                    var token = (response.Data as JObject).First.Values().FirstOrDefault()?.ToString();
                    _token = token;
                }
                client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _token);
            }
        }
示例#2
0
文件: Form1.cs 项目: GTez/Hello-World
 private void button2_Click(object sender, EventArgs e)
 {
     Client client1 = new Client();
     client1.Age = 15;
     client1.Name = "Adam";
 }
        internal Client GetApiClient(HttpClient client)
        {
            var nswagClient = new MyNamespace.Client(client.BaseAddress.ToString(), client);

            return(nswagClient);
        }