Not sure whats going on here. Bit of a newb to API's and REST. I made an API that's working but the location is returning null?
code:
using (var client = new HttpClient()) { client.BaseAddress = new Uri(BaseEndPoint); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response; Console.WriteLine("POST"); User NewUser = new User(); NewUser.Email = "TestUser999@email.com"; NewUser.Handle = "TestUser999"; NewUser.Password = "12345"; NewUser.FirstName = "Test99"; NewUser.LastName = "User99"; NewUser.Address = "366 South Myrtle"; NewUser.City = "Kankakee"; NewUser.State = "IL"; NewUser.Zip = 60901; NewUser.JoinDate = DateTime.Now; NewUser.Ban = false; NewUser.UserPoints = 100; response = await client.PostAsJsonAsync("api/user", NewUser); if (response.IsSuccessStatusCode) { Uri userURL = response.Headers.Location; Console.WriteLine(userURL); Console.WriteLine("PUT");//currently Location Not Returning NewUser.UserPoints = 999; response = await client.PutAsJsonAsync(userURL, NewUser); Console.WriteLine("DELETE");//currently Location Not Returning response = await client.DeleteAsync(userURL); }
Screenshot