Sending a file to an API - C#
Posted
by alex
on Stack Overflow
See other posts from Stack Overflow
or by alex
Published on 2010-05-17T16:10:21Z
Indexed on
2010/05/17
18:20 UTC
Read the original article
Hit count: 133
I'm trying to use an API which sends a fax.
I have a PHP example below: (I will be using 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 build a post request?
Ideally, i was trying to do this using REST - and constructing a URL, and using HttpWebRequest (GET) to call the API
© Stack Overflow or respective owner