Tuesday, March 12, 2013

NotSupportedException during HTTP Post - EndGetRequestStream


If you're making an HTTP Post on WP7/WP8 and you get back an annoying NotSupportedException, then one thing i might be is that you forgot to Flush/Close/Dispose the Request stream.

i.e. make sure that you do the `using` part of:

client.BeginGetRequestStream(state =>
{
try
{
using (var dataStream = client.EndGetRequestStream(state))
{
dataStream.Write(postData, 0, postData.Length);
dataStream.Flush();
}
client.BeginGetResponse(respState =>
{
try
{
var response = client.EndGetResponse(respState);
// ...
view raw snip.cs hosted with ❤ by GitHub

No comments:

Post a Comment