Thingsboard - REST API 上的身份验证错误(来自 Curl 命令和 ASP.NET)

Thingsboard - Authentication error on REST API (FROM Curl command and ASP.NET)

我可以使用我的凭据登录 Thingsboard 网站,但是当我尝试使用 CURL 命令连接该网站时,出现 "Authentication Failed" 错误。

curl -X POST "https://cloud.thingsboard.io/api/auth/login" -d "{"username":"XYZPQR@ABCDLMN.com", "password":"Q@34&pwn"}" --header "Content-Type: application/json" --header "Accept: application/json"

错误代码

{"status":401,"message":"Authentication failed","errorCode":10,"timestamp":1542893993515}

然而,当我在 ASP.NET 应用程序中使用相同的用户 ID 和密码来获取授权令牌时,我确实获得了 JWT 令牌,但使用相同的令牌我无法创建任何 REST API 来自 Thingsboard 的电话。

ASP.NET核心代码

var response = new HttpResponseMessage();
var client = new HttpClient();                
UserModel model = new UserModel { username = "XYZPQR@ABCDLMN.com", password = "Q@34&pwn" };
var content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");

response = await client.PostAsync("https://cloud.thingsboard.io/api/auth/login", content);

string data = await response.Content.ReadAsStringAsync();

var userToken = JsonConvert.DeserializeObject<UserToken>(data);

MediaTypeWithQualityHeaderValue contentType = new MediaTypeWithQualityHeaderValue("application/json");

client.DefaultRequestHeaders.Accept.Add(contentType);

client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", userToken.token);
Uri url = new Uri("https://cloud.thingsboard.io/api/plugins/telemetry/DEVICE/431be6e0-e8ca-11e8-9e5c-3d544ba4fdfc/values/timeseries?keys=Electricity");

response = await client.GetAsync(url);

型号Class

 public class UserModel {
        public string username { get; set; }
        public string password { get; set; }
    }

    public class UserToken
    {
        public string token { get; set; }
        public string refreshToken { get; set; }
    }

请建议如何从 Thingsboard REST 获取遥测值 API。

这是我犯的一个小错误;我将旧代码更改为新代码(如下所示),一切都按预期开始工作。

旧代码

client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", userToken.token);

新代码

client.DefaultRequestHeaders.Add("X-Authorization", "Bearer " + userToken.token);

感谢支持。