'System.Net.HttpWebRequest' does not contain a definition for 'GetRequestStream'

后端 未结 1 1031
清酒与你
清酒与你 2020-12-19 02:15

I am new to both C# and Windows phone and am trying to make a small app that performs a JSON request. I am following the example in this post https://stackoverflow.com/a/498

1条回答
  •  一生所求
    2020-12-19 02:23

    HttpWebRequest doesn't have a GetRequestStream or GetRequestStreamAsync in WP8. Your best bet is to create a Task and await on it, like so:

    using (var stream = await Task.Factory.FromAsync(request.BeginGetRequestStream, request.EndGetRequestStream, null))
    {
        // ...
    }
    

    Edit: as you've mentioned that you're new to C#, you would need to have your login method be async to use the await keyword:

    public async Task LoginAsync()
    {
        // ...
    }
    

    Callers to login would need to use the await keyword when calling:

    string result = await foo.LoginAsync();
    

    Here's a good primer on the subject: http://msdn.microsoft.com/en-us/library/vstudio/hh191443.aspx

    0 讨论(0)
提交回复
热议问题