Recently I was tasked with developing a plugin that would send information from Microsoft Dynamics 365 to a REST API. Originally, I had developed this plugin in an on-premise environment, which caused issues for when I eventually needed to move it to an Online instance. I will discuss more on this shortly.
To work around this problem, I decided to change my web request code to use the DataContractJsonSerializer class instead. Doing this meant I would need to add DataContract and DataMember attributes to the object classes and slightly alter the data that is being passed into the request.
After making this change I could send web requests to a REST API from my plugin. The code above is the method I used to accomplish this, which made multiple Post requests and passed in multiple DataContract objects.