Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.NET Api客户端_C#_Asp.net_Api - Fatal编程技术网

C# ASP.NET Api客户端

C# ASP.NET Api客户端,c#,asp.net,api,C#,Asp.net,Api,我正在学习如何创建WEB-API客户端 我创建了一些简单的API: [HttpGet] public IHttpActionResult GetInfo() { return Ok("Its working!"); } [HttpPost] public IHttpActionResult PostInfo(ClientDataDto dto) { t

我正在学习如何创建WEB-API客户端

我创建了一些简单的API:

[HttpGet]
        public IHttpActionResult GetInfo()
        {
            return Ok("Its working!");
        }
        [HttpPost]
        public IHttpActionResult PostInfo(ClientDataDto dto)
        {

            try
            {
                someMethod(dto.IdKlienta, dto.Haslo, dto.IdZgloszenia, dto.HardwareInfo, dto.SoftwareInfo);

                return Ok("sent");
            }
            catch
            {
                return BadRequest();
            }
        }
现在我只想调用GET方法。 当我将Fiddler与addr一起使用时 localhost:someport/api/Client2 它起作用了

但是,当我尝试通过客户端执行此操作时,下面是哪种代码:

private static HttpClient client = new HttpClient();

        static void Main(string[] args)
        {
            #region TESTONLY
            var debug = new XMLData();
            string HardwareInfoXML = debug.HardwareXML;
            string SoftInfoXML = debug.SoftwareXML;
            int id_zgloszenia = 20;
            int idKlienta = 25;
            //haslo = "202cb962ac59075b964b07152d234b70";
            #endregion

            var data = new ClientDataDto() { HardwareInfo = HardwareInfoXML, SoftwareInfo = SoftInfoXML, IdKlienta = idKlienta, IdZgloszenia = id_zgloszenia };
            RunAsync(data);

        }





        private static async Task RunAsync(ClientDataDto data)
        {
            var stringContent = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json");

            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.BaseAddress = new Uri(@"http://localhost:7774/api/client2/");
            var url = new Uri(@"http://localhost:7774/api/client2/");

            var res1 = await client.GetAsync(url);
            var res = await client.PostAsync(url, stringContent);
            res.EnsureSuccessStatusCode();

        }
在没有任何信息的情况下关闭应用程序

var res1 = await client.GetAsync(url);
我已经检查了调试异常窗口中的所有异常,但在尝试调用GetAsync后它刚刚关闭 PostASync也不起作用


这里怎么了?

我真的很抱歉我发布了simpe问题。 sulotion是在RunAsync(数据)上添加.Wait()

  RunAsync(data).Wait();