'How to simulate api calls in C# using php file

I have an online reports viewer application that stores patients records as follows:

Web application view: enter image description here

I have created a C# application that is meant to capture patient details from user:

C# application view: enter image description here

C# application is supposed to capture & post data to the web application using a php file called "med-demo.php" with the following code to simulate api calls:

<?php 

$post['api_id']="xxxx";
$post['api_key']="xxxx";

// Set customer data
$post['customer_system_id']="11221";
$post['customer_name']="New Customer 1";
$post['customer_email']="[email protected]";

// Set report data
$post['case_id']="123458";
$post['patient_cpr']="965847365";
$post['patient_name']="John Doe";
$post['patient_mrn']="5556632";

// Create report object
$post['report_file']= curl_file_create(realpath('small-logo.png'));

// Assign POST data
$ch = curl_init("url");

$headers = array();
$headers[] = 'Content-Type: multipart/form-data';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post);

// Receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close ($ch);

print_r(json_decode($response,true));

?>

** API ID/KEY + curl_init url are omitted for confidentiality.

I have done many searches on how to use the above PHP file (in my C# application) to post the data to the web application but no luck. I'm really new to the api/web part.

Would very much appreciate if someone could guide me through simulating API calls using the PHP file to post the data from C# to web application.

Thank you!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source