0

I am trying to POST some JSON data to my Server. I am using simple code which I have attained from: Http Post for Windows Phone 8

Code:

        string url = "myserver.com/path/to/my/post";

        // HTTP web request
        var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
        httpWebRequest.ContentType = "text/plain; charset=utf-8";
        httpWebRequest.Method = "POST";

        // Write the request Asynchronously 
        using (var stream = await Task.Factory.FromAsync<Stream>(httpWebRequest.BeginGetRequestStream,
                                                                 httpWebRequest.EndGetRequestStream, null))
        {
            //create some json string
            string json = "{ \"my\" : \"json\" }";

            // convert json to byte array
            byte[] jsonAsBytes = Encoding.UTF8.GetBytes(json);

            // Write the bytes to the stream
            await stream.WriteAsync(jsonAsBytes, 0, jsonAsBytes.Length);
        }

I am getting an error though on await and Task:

enter image description here

Anyone see the obvious error?

Community
  • 1
  • 1
Subby
  • 5,370
  • 15
  • 70
  • 125

1 Answers1

0

Fixed it by changing method signature to:

public async Task ReportSighting(Sighting sighting)

Subby
  • 5,370
  • 15
  • 70
  • 125