如何从c#中的控制台应用程序调用服务

时间:2017-03-24 10:19:07

标签: c# c#-4.0

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

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

2 个答案:

答案 0 :(得分:0)

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 Ask Questions

答案 1 :(得分:0)

          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