Upload file in API C #

I am trying to use the API that sends a fax.

I have a PHP example below: (I will use C #, however)

<?php
//This is example code to send a FAX from the command line using the Simwood API
//It is illustrative only and should not be used without the addition of error checking etc.

$ch = curl_init("http://url-to-api-endpoint");
$fax_variables=array(
'user'=> 'test',
'password'=> 'test',
'sendat' => '2050-01-01 01:00',
'priority'=> 10,
'output'=> 'json',
'to[0]' => '44123456789',
'to[1]' => '44123456780',
'file[0]'=>'@/tmp/myfirstfile.pdf',
'file[1]' => '@/tmp/mysecondfile.pdf'
); 
print_r($fax_variables);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $fax_variables); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec ($ch);
$info = curl_getinfo($ch);
$result['http_code'];
curl_close ($ch);
print_r($result);

?>

My question is in the C # world, how would I achieve the same result?

Do I need to create a mail request?

Ideally, I tried to do this with REST - and constructed the URL, and using HttpWebRequest (GET) to call the API

+3
source share
3 answers

Any time you send data, you should use POST. This is technology independent. All standard http methods (POST, GET, PUT, DELETE) are supported by the idea of ​​REST.

See this entry on the wiki .


:

. , , , HttpWebRequest . (), - .

WCF. Microsoft . ' .

+1

URL- HTTP/S #, Curl . . .. Curl , URL- Post. Curl , , # -.

0

Based on published specifications, the HttpWebRequest object is what you should use to communicate with Simwood api using C #.

0
source

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