0

我正在尝试将一些 JSON 数据发布到我的服务器。我正在使用我从中获得的简单代码:Windows Phone 8 的 Http Post

代码:

        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);
        }

我得到一个错误,虽然awaitTask

在此处输入图像描述

有人看到明显的错误吗?

4

1 回答 1

0

通过将方法签名更改为:

公共异步任务 ReportSighting(Sighting Sighting)

于 2013-09-15T01:03:56.250 回答