I have a generic Windows project with several API calls. One method refuses to work because my other calls work exactly like that. I tried the using keyword to solve the problem.
Function:
public async Task<User> GetNewUser(string user_guid, OAuthTokens OAuth) { String userguidJSON = VALIDJSON_BELIEVE_ME; using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Authorization", Encrypt(OAuth.Accesstoken)); using (HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Post, BASE_URL + URL_USERS + "/data")) { req.Content = new StringContent(userguidJSON, Encoding.UTF8, "application/json"); await httpClient.SendAsync(req).ContinueWith(respTask => { Debug.WriteLine(req.Content.ReadAsStringAsync());
EDIT
public async Task<User> GetNewUser(string user_guid, OAuthTokens OAuth) { String userguidJSON = VALIDJSON_BELIEVE_ME; using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Authorization", Encrypt(OAuth.Accesstoken)); using (HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Post, BASE_URL + URL_USERS + "/data")) { req.Content = new StringContent(userguidJSON, Encoding.UTF8, "application/json"); await httpClient.SendAsync(req); var result = await req.Content.ReadAsStringAsync();
Stacktrace element
at System.Net.Http.HttpContent.CheckDisposed() at System.Net.Http.HttpContent.ReadAsStringAsync() at Roadsmart.Service.RoadsmartService.<GetNewUser>d__2e.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Roadsmart.ViewModel.SettingsPageViewModel.<SetNewProfilePicture>d__1e.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__3(Object state) at System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()
source share