我正在尝试使用REST API,C#和RestSharp库为Jira问题添加一个观察者。
根据Jira's documentation,要添加的观察者的名称必须采用以下格式:" username" (只是双引号内的值,没有名称)。
这显然不是Json。
通过关注this answer,我可以使用Curl为Jira问题添加一个观察者:
curl -i -u myusername:mypassword -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d "\"myusername\"" http://my.jira.host/rest/api/2/issue/MYISSUEKEY-1/watchers
然而,它不适用于RestSharp(Jira回答错误的请求)。到目前为止,这是我的代码:
private RestRequest CreateRequest(Method method, String path)
{
var request = new RestRequest { Method = method, Resource = path, RequestFormat = DataFormat.Json, };
request.AddHeader("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(String.Format("{0}:{1}", username, password))));
return request;
}
public void AddWatcher(string issueKey, string watcher)
{
try
{
var path = String.Format("issue/{0}/watchers", issueKey);
var request = CreateRequest(Method.POST, path);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Accept", "application/json");
request.AddBody(string.Format("\"{0}\"", watcher));
var response = client.Execute(request);
AssertStatus(response, HttpStatusCode.NoContent);
}
catch (Exception ex)
{
Trace.TraceError("AddWatcher(issue, watcher) error: {0}", ex);
throw new JiraClientException("Could not add watcher", ex);
}
}
我想知道是否可以通过RestSharp发送该类型的POST,即使它不是名称/值对。
由于