public RefreshAccessToken ( string refreshToken ) : Task |
||
refreshToken | string | |
Результат | Task |
public async Task<Result> PostData(Uri uri, StringContent content, UserAuthenticationEntity userAuthenticationEntity, string language = "ja") { using (var httpClient = new HttpClient()) { try { var authenticationManager = new AuthenticationManager(); Result result = new Result(false, ""); if (RefreshTime(userAuthenticationEntity.ExpiresInDate)) { var tokens = await authenticationManager.RefreshAccessToken(userAuthenticationEntity.RefreshToken); result.Tokens = tokens.Tokens; } httpClient.DefaultRequestHeaders.Add("Accept-Language", language); httpClient.DefaultRequestHeaders.Add("Origin", "http://psapp.dl.playstation.net"); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", userAuthenticationEntity.AccessToken); var response = await httpClient.PostAsync(uri, content); var responseContent = await response.Content.ReadAsStringAsync(); result.IsSuccess = response.IsSuccessStatusCode; result.ResultJson = responseContent; return result; } catch (Exception) { return new Result(false, string.Empty); } } }
public async Task <Result> GetData(Uri uri, UserAuthenticationEntity userAuthenticationEntity, string language = "ja") { using (var httpClient = new HttpClient()) { try { var authenticationManager = new AuthenticationManager(); Result result = new Result(false, ""); if (RefreshTime(userAuthenticationEntity.ExpiresInDate)) { var tokens = await authenticationManager.RefreshAccessToken(userAuthenticationEntity.RefreshToken); result.Tokens = tokens.Tokens; } httpClient.DefaultRequestHeaders.Add("Origin", "http://psapp.dl.playstation.net"); httpClient.DefaultRequestHeaders.Add("Accept-Language", language); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", userAuthenticationEntity.AccessToken); var response = await httpClient.GetAsync(uri); var responseContent = await response.Content.ReadAsStringAsync(); result.IsSuccess = response.IsSuccessStatusCode; result.ResultJson = responseContent; return(result); } catch (Exception ex) { // TODO: Add detail error result to json object. return(new Result(false, string.Empty)); } } }
public async Task <Result> PostData(Uri uri, StringContent content, UserAuthenticationEntity userAuthenticationEntity, string language = "ja", bool isMessage = false) { var handler = new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }; using (var httpClient = new HttpClient(handler)) { try { var authenticationManager = new AuthenticationManager(); Result result = new Result(false, ""); if (RefreshTime(userAuthenticationEntity.ExpiresInDate)) { var tokens = await authenticationManager.RefreshAccessToken(userAuthenticationEntity.RefreshToken); result.Tokens = tokens.Tokens; } if (isMessage) { httpClient.DefaultRequestHeaders.Add("User-Agent", "PlayStation Messages App/3.20.23"); } httpClient.DefaultRequestHeaders.Add("Accept-Language", language); httpClient.DefaultRequestHeaders.Add("Origin", "http://psapp.dl.playstation.net"); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", userAuthenticationEntity.AccessToken); var response = await httpClient.PostAsync(uri, content); var responseContent = await response.Content.ReadAsStringAsync(); result.IsSuccess = response.IsSuccessStatusCode; result.ResultJson = responseContent; return(result); } catch (Exception) { return(new Result(false, string.Empty)); } } }
public async Task<Result> PostData(Uri uri, MultipartContent content, UserAuthenticationEntity userAuthenticationEntity, string language = "ja", bool isMessage = false) { using (var httpClient = new HttpClient()) { try { var authenticationManager = new AuthenticationManager(); Result result = new Result(false, ""); if (RefreshTime(userAuthenticationEntity.ExpiresInDate)) { var tokens = await authenticationManager.RefreshAccessToken(userAuthenticationEntity.RefreshToken); result.Tokens = tokens.Tokens; } if (isMessage) { httpClient.DefaultRequestHeaders.Add("User-Agent", "PlayStation Messages App/3.20.23"); } httpClient.DefaultRequestHeaders.Add("Accept-Language", language); httpClient.DefaultRequestHeaders.Add("Origin", "http://psapp.dl.playstation.net"); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", userAuthenticationEntity.AccessToken); var response = await httpClient.PostAsync(uri, content); var responseContent = await response.Content.ReadAsStringAsync(); result.IsSuccess = response.IsSuccessStatusCode; result.ResultJson = responseContent; return result; } catch { // TODO: Add detail error result to json object. return new Result(false, string.Empty); } } }