Reputation: 1532
I need to post data to server, and get compressed data back from it.
I am using windows phone 7 sdk.
I read that it can be done using SharpGIS or Coding4Fun toolkit.
They use WebClient (AFAIK).
can anyone help me?
Here's what I need to do-
Post data(XML) to url
Get compressed data (only GZip supported by server) in the form of xml string/stream
deserialise the xml data received
and the methods should be awaitable.
Upvotes: 0
Views: 460
Reputation: 10600
I don't use Windows 8, which means Windows Phone SDK is only on VS 2010, which doesn't support the Microsoft HttpClient.
There's a NuGet package Delay.GZipWebClient written by an MS dev that adds simple support for it. So far it's worked like a charm.
Upvotes: 0
Reputation: 280
WebClient and HttpWebRequest for C4F toolkit are supported. HttpClient doesn't exist without http client library currently in WP.
Upvotes: 1
Reputation: 2111
When I had to do this in wp7, I
With in the portable class library
public class PostData
{
public async Task<T> TestMe<T>(XElement xml)
{
var client = new HttpClient(new HttpClientHandler
{
AutomaticDecompression = DecompressionMethods.GZip
| DecompressionMethods.Deflate
});
var response = await client.PostAsync("https://requestUri", CreateStringContent(xml));
var responseString = await response.RequestMessage.Content.ReadAsStringAsync();
//var responseStream = await response.RequestMessage.Content.ReadAsStreamAsync();
//var responseByte = await response.RequestMessage.Content.ReadAsByteArrayAsync();
return JsonConvert.DeserializeObject<T>(responseString);
}
private HttpContent CreateStringContent(XElement xml)
{
return new StringContent(xml.ToString(), System.Text.Encoding.UTF8, "application/xml");
}
}
Upvotes: 1