我用 RestSharp 解决了这个问题。这是 REST API 的简单工具。当我发送带有附件的票时,我使用以下代码:
var client = new RestClient(_freshdeskUrl);
client.Authenticator = new HttpBasicAuthenticator(_apiKey, "X");
var request = new RestRequest("", Method.POST);
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "multipart/form-data");
request.AddParameter("email", "example@example.com");
request.AddParameter("subject", "Subject");
request.AddParameter("description", "Description");
request.AddParameter("name", "Name");
request.AddParameter("status", "2");
request.AddParameter("priority", "1");
request.AddFile("attachments[]", bytes, "Logs.txt", "text/plain");
var response = client.Execute(request);
当我发送不带附件的票时,我使用以下代码:
RestClient client = new RestClient(_freshdeskUrl);
client.Authenticator = new HttpBasicAuthenticator(_apiKey, "X");
RestRequest request = new RestRequest("", Method.POST);
request.AddHeader("Accept", "application/json");
request.AddJsonBody(new
{
email = "example@example.com",
subject = "Subject",
description = "Description",
name = "Name",
status = 2,
priority = 1
});
var response = client.Execute(request);