I am trying to fulfill this rest api:
public async Task<bool> AddTimetracking(Issue issue, int spentTime)
{
// POST /rest/issue/{issue}/timetracking/workitem
var workItem = new WorkItem(spentTime, DateTime.Now);
var httpContent = new StringContent(workItem.XDocument.ToString());
var requestUri = string.Format("{0}{1}issue/{2}/timetracking/workitem", url, YoutrackRestUrl, issue.Id);
var respone = await httpClient.PostAsync(requestUri, httpContent);
if (!respone.IsSuccessStatusCode)
{
throw new InvalidUriException(string.Format("Invalid uri: {0}", requestUri));
}
return respone.IsSuccessStatusCode;
}
workItem.XDocument
contains the following elements:
<workItem>
<date>1408566000</date>
<duration>40</duration>
<desciption>test</desciption>
</workItem>
I am getting an error from the API: Unsupported Media Type
I really have no idea how to resolve this, help is greatly appreciated. How do I marshall an XML file via a HTTP POST URI, using HttpClient
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…