【问题标题】:How to call a service from console Application in c#如何在 C# 中从控制台应用程序调用服务
【发布时间】:2017-03-24 10:19:06
【问题描述】:

我有服务“http://deveqtradedb.lazard.com/API.aspx?action=export&entity=global

我想从控制台应用程序的 Main() 函数调用这个服务

【问题讨论】:

  • 知道自己想做什么是好事。但是你的问题是什么?
  • 您的链接无效。获得更多信息会很有帮助。您已经尝试过什么,您想调用什么类型的服务?
  • 是什么让您认为从控制台应用程序调用它有什么不同?
  • 想在控制台应用程序运行时从该服务获取结果
  • 请告诉我如何从 Main() 函数调用此类服务​​

标签: c# c#-4.0


【解决方案1】:
          HttpWebRequest req = null;
          HttpWebResponse resp = null;
          string baseaddress = "http://deveqtradedb.lazard.com/API.aspx?action=export&entity=global";
         req = (HttpWebRequest)WebRequest.Create(baseaddress);
         req.Method = "POST";
         req.ContentType = "text/xml; encoding = UTF-8";
         resp = req.GetResponse() as HttpWebResponse;
  1. 检查这里

    https://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.getresponse(v=vs.110).aspx

【讨论】:

    【解决方案2】:
    HttpClient client = new HttpClient();
    string url = "http://deveqtradedb.lazard.com/API.aspx?action=export&entity=global";
    string response = client.GetStringAsync(url).Result;
    

    进一步阅读:

    1. Calling a Web API From a .NET Client (C#)
    2. How to s

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-29
      • 1970-01-01
      • 2021-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-14
      相关资源
      最近更新 更多