Response.content.readasasync返回null [英] Response.content.readasasync returns null

查看:381
本文介绍了Response.content.readasasync返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 response.content.readasasync返回总是null帮助请:))

我尝试过:

<预> public class ResultData
{
public string Name {get;组; }

public List< Bank> RresultObject {get;组; }

public string UUId {get;组; }


public string FirstName {get;组; }

public string LastName {get;组; }

公共字符串地址{get;组; }

public string tel {get;组; }

公共字符串Marital_status {get;组; }

public string Occupation {get;组; }

公共字符串PayIN {get;组; }
}





< pre> static async Task CallWebAPIAsync()
{

try
{
using(var client = new HttpClient())
{
client。 BaseAddress = new Uri(http:// localhost:35799 /);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(application / json));

// GET方法
HttpResponseMessage响应= await client.GetAsync(bank);
if(response.IsSuccessStatusCode)
{
//此处始终为null< - < - < -
ResultData department = await response.Content.ReadAsAsync< ResultData>( );

}
}
Console.Read();

}
catch(exception ex)
{
throw ex;
}

}

解决方案

打开此网址时的响应是什么 [ http:// localhost :35799 /银行]

response.content.readasasync returns always null help please :))

What I have tried:

<pre> public class ResultData
    {
        public string Name { get; set; }

        public List<Bank> RresultObject { get; set; }

        public string UUId { get; set; }


        public string FirstName { get; set; }

        public string LastName { get; set; }

        public string address { get; set; }
       
        public string tel { get; set; }

        public string Marital_status { get; set; }

        public string Occupation { get; set; }

        public string PayIN { get; set; }
    }



<pre> static async Task CallWebAPIAsync()
        {

            try
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri("http://localhost:35799/");
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    //GET Method
                    HttpResponseMessage response = await client.GetAsync("bank");
                    if (response.IsSuccessStatusCode)
                    {
                        // here always null <-<-<-
                        ResultData department = await response.Content.ReadAsAsync<ResultData>();
                      
                    }
                }
                Console.Read();

            }
            catch (Exception ex)
            {
                throw ex;
            }
           
        }

解决方案

What is the response if you open this url [http://localhost:35799/bank]?


这篇关于Response.content.readasasync返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆