如何使用指定的参数从Windows服务调用API? [英] How to call API from windows service with specified parameter?
本文介绍了如何使用指定的参数从Windows服务调用API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发Windows服务,我需要从同一服务中调用webAPI。
我有什么,
I am working on windows service, and I need to call webAPI from the same service.
What I have,
API - http://some address
Method Name-MyMethod
Variable1 - id|location|5|card
Variable2 Types="getpoints"
我是新来的,所以我不知道如何开始。
请建议我代码或任何有关上述文章。
我尝试过:
I am new to this so I dont know how to start.
Please suggest me code or any article regarding above.
What I have tried:
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://some address");
// Usage
HttpResponseMessage response = client.GetAsync("api/importresults/1").Result;
if (response.IsSuccessStatusCode)
{
var dto = response.Content.ReadAsAsync<ImportResultDTO>().Result;
//var dto = response.Content.ReadAsByteArrayAsync();
}
else
{
Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
//MessageBox.Show("{0}({1})", (int)response.StatusCode, response.ReasonPhrase);
}
这种方法没有给出任何响应而没有任何错误。
this method not giving any response not any error.
推荐答案
参见从.NET客户端调用Web API(C#)| Microsoft Docs [ ^ ]。
这篇关于如何使用指定的参数从Windows服务调用API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文