public class UserTokenDto { public Result result { get; set; } public object targetUrl { get; set; } public bool success { get; set; } public object error { get; set; } public bool unAuthorizedRequest { get; set; } public bool __abp { get; set; } }
public class Result { public string accessToken { get; set; } public string encryptedAccessToken { get; set; } public int expireInSeconds { get; set; } public int userId { get; set; } public int authCode { get; set; } }
var data= await "http://xxxxxx/api/services/app/PublicityItem/GetPublicityItemFirstUnsynchronized".WithOAuthBearerToken(response.result.accessToken).GetAsync().ReceiveJson<CertInfoDataDto>();
var client = new RestClient("http://bqp.natapp1.cc/api/"); var request = new RestRequest("TokenAuth/Authenticate", Method.POST); var json = JsonConvert.SerializeObject(new { usernameOrEmailAddress = "admin", password = "123qwe" }); request.AddParameter("application/json", json, ParameterType.RequestBody); var response = client.Execute(request); var user = JsonConvert.DeserializeObject<UserTokenDto>(response.Content);
第二步调用数据同步接口
1 2 3
var restRequest = new RestRequest("services/app/PublicityItem/GetPublicityItemFirstUnsynchronized", Method.GET); restRequest.AddHeader("Authorization", $"Bearer {user.result.accessToken}"); var restResponse = client.Execute(restRequest);