Dónde está HttpContent.¿ReadAsAsync?
Veo en toneladas de ejemplos en la web usando el nuevo objeto HttpClient
(como parte de la nueva API Web) que debería haber un método HttpContent.ReadAsAsync<T>
. Sin embargo, MSDN no menciona este método, ni IntelliSense lo encuentra.
¿A dónde fue, y cómo trabajo alrededor de él?
5 answers
Parece que es un método de extensión (en System.Net.Http.Formatting):
Actualización:
PM> instalar-paquete Microsoft.AspNet.WebAPI.Cliente
De acuerdo con la página del paquete System.Net.Http.Formatting NuGet, el paquete System.Net.Http.Formatting
ahora es heredado y en su lugar se puede encontrar en el paquete Microsoft.AspNet.WebApi.Client
disponible en NuGet aquí.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-12-08 23:24:26
Tengo el mismo problema, así que simplemente me string JSON y deserializar a mi clase:
HttpResponseMessage response = await client.GetAsync("Products");
//get data as Json string
string data = await response.Content.ReadAsStringAsync();
//use JavaScriptSerializer from System.Web.Script.Serialization
JavaScriptSerializer JSserializer = new JavaScriptSerializer();
//deserialize to your class
products = JSserializer.Deserialize<List<Product>>(data);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-06-05 05:18:43
Si ya está usando Newtonsoft.Json
y no desea instalar Microsoft.AspNet.WebApi.Client
:
var myInstance = JsonConvert.DeserializeObject<MyClass>(
await response.Content.ReadAsStringAsync());
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-02-11 19:21:13
Simplemente haga clic derecho en su proyecto para administrar paquetes NuGet buscar Microsoft.AspNet.WebAPI.Instalarlo cliente y usted tendrá acceso al método de extensión.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-01-11 21:12:25
Después de haber golpeado este un par de veces y seguido un montón de sugerencias, si no lo encuentra disponible después de instalar el Microsoft NuGet.AspNet.WebAPI.El cliente agrega manualmente una referencia desde la carpeta packages en la solución a:
\Microsoft.AspNet.WebApi.Client.5.2.6\lib\net45\System.Net.Http.Formatting.dll
Y no caer en la trampa de añadir referencias antiguas a la System.Net.Http.Formatting.dll NuGet
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-10-05 07:31:34