使用 C# 集成 RingCentral FaxOut API

本文关键字:FaxOut API RingCentral 集成 使用 | 更新日期: 2023-09-27 18:30:52

嗨,你好吗?我正在尝试使用传真输出 API:

http://service.ringcentral.com/faxoutapi/

这就是关于 API 的整个文档。基本上我需要发送一个带有一些数据的 HTTP POST。

这是我的代码,但我无法让它工作,请告诉我是否有我没有看到的东西。

string URLAuth = "https://service.ringcentral.com/faxapi.asp";
WebClient webClient = new WebClient();
var formData = new NameValueCollection();
formData["Username"] = "2487955151";
formData["Password"] = "mypassword";
formData["Recipient"] = "12485974888";
formData["Coverpagetext"] = "Some random text";
formData["Resolution"] = "High";
byte[] responseBytes = webClient.UploadValues(URLAuth, "POST", formData);
string resultAuthTicket = Encoding.UTF8.GetString(responseBytes);
webClient.Dispose();
return resultAuthTicket;

谢谢!

使用 C# 集成 RingCentral FaxOut API

我已经集成了Popfax服务,该服务还提供传真API,http://www.popfax.com/index.php?pop=corporate&corp=free_api 它与我们的应用程序完美配合。我相信您的软件也会如此。唯一的条件是有一个清晰的代码。

您的代码可能无法正常工作,因为WebClient.UploadValues()可能会创建和发送内容类型设置为 application/x-www-form-urlencoded 的请求,而 API 需要multipart/form-datamultipart/form-data是发送文件时流行的内容类型。

下面是一些使用 System.Net.Http(和System.IO)发送multipart/form-data请求的工作 C# 代码。

string url = "https://service.ringcentral.com/faxapi.asp";
var data = new MultipartFormDataContent();
data.Add(new StringContent("16501112222"), "username");
data.Add(new StringContent("mypassword"), "password");
data.Add(new StringContent("16501113333"), "recipient");
data.Add(new StringContent("RingCentral FaxOut API using C#"), "coverpagetext");
data.Add(new ByteArrayContent(File.ReadAllBytes("C:''path''to''test.pdf", "attachment", "test.pdf");
var client = new HttpClient();
var response = client.PostAsync(new Uri(url), data).Result;
if (response.IsSuccessStatusCode)
{
    var responseContent = response.Content;
    var responseString = responseContent.ReadAsStringAsync().Result;
    Console.WriteLine(responseString);
}

您还可以使用更广泛的RingCentral平台API,其中包括传真等。

使用 ncToolControlsASP.NET

。.aspx:

<%@ Register Assembly="ncToolControls" Namespace="ncToolControls" TagPrefix="nc" %>
<nc:FaxService ID="fsCtrl" AddCloseButton="true" CssClass="mobilestyle_input" Width="620px" runat="server" />  
<p align="center"><asp:Literal ID="lit_Message" runat="server"></asp:Literal></p>              

代码隐藏.cs

protected void Page_Init(object sender, EventArgs e)
{
    this.fsCtrl.btnCloseFax.Click += new EventHandler(btnCloseFaxScreen_Click);
}
protected void Page_Load(object sender, EventArgs e)
{
    this.fsCtrl.eFaxServer_Name = "rcfax.com";
    this.fsCtrl.Host_Server_Name = "smtp.domain.com";
    this.fsCtrl.Assiged_Email = "Authenticated Email Goes Here";
    this.fsCtrl.AssigedEmail_Password = "Password Goes Here";        
    this.fsCtrl.HostServer_PortNumber = 25;
    this.fsCtrl.HostServerRequireAuthentication = false;
    this.fsCtrl.HostServerRequireSSL = false;
    this.fsCtrl.HostServerRequiresInternationalDigit = false;
    this.fsCtrl.Company_FaxNumber = "12125555555";
    this.fsCtrl.FaxOut_FolderPath = "~/faxout/";  //- Folder must be valid path in Virtual Directory

    if (!Page.IsPostBack)
    {
    }
    btnSave_Click(sender, e);                
}

在此处下载示例和控件http://www.netstair.net/download/RingCentral-Fax.zip