-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextra_5_send_individual_fax_dotnet_35.cs
50 lines (42 loc) · 1.49 KB
/
extra_5_send_individual_fax_dotnet_35.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
namespace Interfax_35_sample
{
class Program
{
static void Main(string[] args)
{
// Your credentials
const string username = "username";
const string password = "password";
// The fax you want to send
const string faxFilePath = "fax.pdf";
// The API method to call
const string baseUri = "https://rest.interfax.net";
string uploadUri = "/outbound/faxes";
// Set the parameters as per
// https://www.interfax.net/en/dev/rest/reference/2918
var options = new Dictionary<String, String>(){
{"faxNumber", "+11111111112"}
};
// Create a new web client for making API calls
WebClient webClient = new WebClient();
// Build the URL with the options defined earlier
uploadUri += "?";
foreach (var x in options.Keys)
{
uploadUri += x + '=' + options[x] + '&';
}
// Add the credentials to the headers
var encodedAuth = Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password));
webClient.BaseAddress = baseUri;
webClient.Headers.Add(HttpRequestHeader.Authorization, "Basic " + encodedAuth);
webClient.Headers.Add(HttpRequestHeader.Accept, "application/json");
webClient.Headers.Add(HttpRequestHeader.ContentType, "application/pdf");
// Submit the file
var result = webClient.UploadFile(uploadUri, "post", faxFilePath);
}
}
}