How to make an http call from a class in a C # class library?

I am writing Job Schedulerusing the library Quartzat C#. My requirement is that if the business condition is met, I need to call the server Apple.

Here's what my planner looks like: -

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);
    }
}

So how to solve this requirement?

Note: -
I would not prefer to move this to an API or web project, since this scheduler will be called from the Web and API commands and others (and).

Thank.

+4
source share
1 answer

If it is not available in your class, most likely you just need to add the link at the top or slightly change your line.

new HttpClient(); new System.Net.Http.HttpClient();. , Visual Studio ( , ) :)

, , , :)

+1

Source: https://habr.com/ru/post/1676365/


All Articles