httpcontent

Read HttpContent in WebApi controller

混江龙づ霸主 提交于 2019-11-26 15:29:33
问题 How can I read the contents on the PUT request in MVC webApi controller action. [HttpPut] public HttpResponseMessage Put(int accountId, Contact contact) { var httpContent = Request.Content; var asyncContent = httpContent.ReadAsStringAsync().Result; ... I get empty string here :( What I need to do is: figure out "what properties" were modified/sent in the initial request (meaning that if the Contact object has 10 properties, and I want to update only 2 of them, I send and object with only two

How do I set up HttpContent for my HttpClient PostAsync second parameter?

ε祈祈猫儿з 提交于 2019-11-26 11:56:18
问题 public static async Task<string> GetData(string url, string data) { UriBuilder fullUri = new UriBuilder(url); if (!string.IsNullOrEmpty(data)) fullUri.Query = data; HttpClient client = new HttpClient(); HttpResponseMessage response = await client.PostAsync(new Uri(url), /*expects HttpContent*/); response.Content.Headers.ContentType = new MediaTypeHeaderValue(\"application/json\"); response.EnsureSuccessStatusCode(); string responseBody = await response.Content.ReadAsStringAsync(); return

Where is HttpContent.ReadAsAsync?

半世苍凉 提交于 2019-11-26 11:54:41
问题 I see in tons of examples on the web using the new HttpClient object (as part of the new Web API) that there should be HttpContent.ReadAsAsync<T> method. However, MSDN doesn\'t mention this method, nor does IntelliSense find it. Where did it go, and how do I work around it? 回答1: It looks like it is an extension method (in System.Net.Http.Formatting): HttpContentExtensions Class Update: PM> install-package Microsoft.AspNet.WebApi.Client According to the System.Net.Http.Formatting NuGet package