Tag: httpcontent

在WebApi控制器中阅读HttpContent

如何在MVC webApi控制器操作中读取PUT请求上的内容。 [HttpPut] public HttpResponseMessage Put(int accountId, Contact contact) { var httpContent = Request.Content; var asyncContent = httpContent.ReadAsStringAsync().Result; … 我在这里得到空string:( 我需要做的是:找出在初始请求中修改/发送的“什么属性”(意思是说,如果Contact对象有10个属性,而我只想更新其中的2个,则只发送两个属性,像这样的东西: { "FirstName": null, "LastName": null, "id": 21 } 预期的最终结果是 List<string> modified_properties = {"FirstName", "LastName"}

如何为我的HttpClient PostAsync第二个参数设置HttpContent?

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 responseBody; } PostAsync需要另一个需要HttpContent参数。 我如何设置一个HttpContent ? 没有任何文档适用于Windows Phone 8。 如果我做GetAsync ,它工作得很好! 但是它需要POST的内容为key =“bla”,something […]

HttpContent.ReadAsAsync在哪里?

我使用新的HttpClient对象(作为新的Web API的一部分)在网上看到大量的例子,应该有HttpContent.ReadAsAsync<T>方法。 但是, MSDN不提这个方法,IntelliSense也没有find它。 它到底在哪里,我该如何解决它?