我正在写Job Scheduler
使用Quartz
库在C#
。我的要求是,如果符合商业条件,我需要拨打Apple
服务器。如何从类库C#中的类进行http调用?
这是我的计划看起来像: -
public class CustomerJob : BaseJob
{
private readonly ICustomerSchedulerService _customerSchedulerService;
public CustomerJob (ICustomerSchedulerService customerSchedulerService)
{
_customerSchedulerService= customerSchedulerService;
}
public override void Execute(IJobExecutionContext context)
{
var customers = _customerSchedulerService.CheckExpiredTask();
foreach(var customer in customers)
{
//I need to make a post request to apple server for each customer
//something like below however there is no HttpClient() available in this class
//var client = new HttpClient();
//client.PostAsync("https://sandbox.itunes.apple.com/verifyReceipt", customer));
}
base.Execute(context);
}
}
那么如何解决这个问题?要求
注: -
我不喜欢这个进入API或基于Web的项目,因为这个调度程序将来自网络& API团队&调用其他(一个或多个)。
谢谢。
如果HttpClient不可用,那么确保你引用了正确的类库,并在你的类的顶部有正确的'using namespace'语句。从类库调用服务与从任何其他地方调用服务没有区别。 – mason