3

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

3 Answers 3

1

Anytime you are sending data you should use a POST. This is regardless of the technology involved. All of the standard http methods (POST, GET, PUT, DELETE) are supported by the idea of REST.

See this wiki entry.


UPDATE: For more info

There are lots of different options. One way, as you described, is to just use the HttpWebRequest object to craft the request and send it. Here's an example of posting data using that method (link), another is here.

An alternative method is to use WCF. Microsoft has some documentation on that here. And O'Reilly has a book on it here.

Sign up to request clarification or add additional context in comments.

Comments

0

I have been interacting with HTTP/S URLs from C# by invoking the Curl utility with the required command line parameters. See this SO answer for more guidance. Curl is purpose-built for this kind of requirement, is tried and true, and can be used from the command-line and batch files to test URLs and Post fields. Let Curl do what it's best at, and leave your C# code for your business logic.

Comments

0

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

1 Comment

yes, but my question is how to send the actual file to the simwood api??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.