0

我正在对 Web 服务 url 进行 HTTP Post 调用。在响应中,我收到 200 Status Ok 消息。但是当我尝试使用 await response.Content.ReadAsStringAsync() 获取响应内容时,它总是'{}'。Web 服务根据传递的用户凭据返回 SUCCESS 或 FAILED。如何检索消息。请帮忙。

进行 Web 服务调用的代码

    public Task<HttpResponseMessage> PostAsJsonAsync<T>(Uri uri, T item)
            {
                var client = new HttpClient();
                var itemAsJson = JsonConvert.SerializeObject(item);
                var content = new StringContent(itemAsJson);
                //var content = new FormUrlEncodedContent(itemAsJson);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Accept.Clear();
                return client.PostAsync(uri, content);

            }

     private async void mainPage_Loaded(object sender, RoutedEventArgs e)
            {
 UserDetails details = new UserDetails()
                {
                    username = composite["username"].ToString(),
                    userpass = composite["password"].ToString()
                };    
    var response = await PostAsJsonAsync(new Uri("http://ec2-xxxx-.compute-1.amazonaws.com:8080/Sanjeevani/rest/SV/login"), details);
                    if (response.IsSuccessStatusCode) //I get a 200 code i.e OK
                    {
                        string str = await response.Content.ReadAsStringAsync();
                        if (str == "SUCCESS") //str is always '{}'
                        {
                            this.Frame.Navigate(typeof(Dashboard), details);
                        }
           }
4

0 回答 0