如何使用System.net.http.httpclient创建新的RT(请求跟踪器票)

时间:2018-01-26 15:49:29

标签: c# httpclient rt

需要开发一个C#应用程序来创建新的RT票证,但https://rt-wiki.bestpractical.com/wiki/REST#C.23上的c#示例代码无效。

我从不同的地方找到了信息,但是没有一个关于如何使用C#HttpClient创建新的rt票证的例子。

这是我的尝试:

private static async void HTTP_Create()
{
        HttpClient client = new HttpClient();
        client.BaseAddress = new Uri(baseURL);

        string ticketUri = string.Format("REST/1.0/ticket/new?user={0}&pass={1}", testUser.UserName, testUser.Password);

        // Doesn't work
        var TicketDataContent = new List<KeyValuePair<string, string>>();
        TicketDataContent.Add(new KeyValuePair<string, string>("id", "ticket/new"));
        TicketDataContent.Add(new KeyValuePair<string, string>("Queue", "queue name"));
        TicketDataContent.Add(new KeyValuePair<string, string>("Requestor", "name@email.com"));
        TicketDataContent.Add(new KeyValuePair<string, string>("Owner", "owner@email.com)"));
        TicketDataContent.Add(new KeyValuePair<string, string>("Subject", "Created by C#"));
        TicketDataContent.Add(new KeyValuePair<string, string>("Text", "Ticket body with messages related to this ticket"));

        var ticketContent = new MultipartFormDataContent();
        ticketContent.Add(new FormUrlEncodedContent(TicketDataContent), "content");
        var response = await client.PostAsync(baseURL + ticketUri, ticketContent);

        Console.WriteLine("Response StatusCode: " + response.StatusCode.ToString());

        var retContent = response.Content;
        var retMsg = await response.Content.ReadAsStringAsync();

        Console.WriteLine(retMsg);
}

我收到了以下回复:

响应状态代码:确定

RT / 4.4.2 200确定

#必需:ID,队列

感谢任何帮助。谢谢!

0 个答案:

没有答案