HttpClient.PostAsync挂起Windows Phone应用程序

时间:2015-04-28 22:29:56

标签: c# rest http windows-phone-8.1 .net-4.5

以下方法可能出现什么问题?整个应用程序在调用“await”行后挂起......

protected async Task<T> PostRequest<T>(string resourceEndpoint, JObject content)
    {
        Uri resourceAddress;
        if (!Helpers.TryGetUri(serviceUri + resourceEndpoint, out resourceAddress))
        {
            return default(T);
        }
        var stringContent = new HttpStringContent(content.ToString());
        HttpResponseMessage response = await httpClient.PostAsync(resourceAddress, stringContent);
        JObject m = JsonConvert.DeserializeObject<JObject>(response.Content.ToString());
        return JsonConvert.DeserializeObject<T>(m["array"].ToString());
    }

我使用这些参数调用了SoapUI的请求,并且进展顺利。

此方法在此处调用:

public async Task<User> Register(string name, string email, string password)
    {
        string path = "";
        JObject content = JObject.FromObject(new RegisterParams() { name = name, email = email, password = password.ToMD5Hash() });
        return await PostRequest<User>(path, content);
    }

那里:

public void Register()
    {
        user = userService.Register(LoginTextBox, EmailTextBox, PasswordTextBox).Result;
    }

0 个答案:

没有答案