400 / 500 error adding worklog in Jira REST API

杀马特。学长 韩版系。学妹 提交于 2019-12-11 03:06:10

问题


I am ready to bang my head off a brick wall so would greatly appreciate any input on this. I am getting the above mentioned errors when I try to add a new worklog. The code to try and add the worklog....

// convert worklog to json string
JavaScriptSerializer serializer = new JavaScriptSerializer();
string data = serializer.Serialize(worklog);

// set up the web request
HttpWebRequest request = WebRequest.Create(baseUrl) as HttpWebRequest;
request.ContentType = "application/json";
request.Method = method;
request.ContentLength = data.Length;

// Authorize user
string base64Credentials =     GetEncodedCredentials(_currentEmployeeUsername_currentEmployeePassword);
request.Headers.Add("Authorization", "Basic " + base64Credentials);
using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
{
writer.Write(data);
}

// return the response
HttpWebResponse response = request.GetResponse() as HttpWebResponse;

The worklog object I am serializing is as follows...

public class WorkLog
{
    public string comment;

    public DateTime started;

    public string timeSpent;
}

The above code gave me a 500 Internal Server error. I've had a browse around lots of questions asked previously and guessed the issue was with the data I am sending. So I've tried a number of variations, one example which had been marked as an answer suggested the following:

"{\"self\": \"http://myservername/rest/api/latest/issue/24469/worklog\", \"author\": {\"self\": \"http://myservername/rest/api/latest/issue/24469/worklog\", \"name\": \"cbourke\", \"displayName\": \"cbourke\", \"active\": false }, \"updateAuthor\": { \"self\": \"http://myservername/rest/api/latest/issue/24469/worklog\", \"name\": \"cbourke\", \"displayName\": \"cbourke\", \"active\": false }, \"comment\": \"Testing.\", \"started\": \"2012-02-15T17:34:37.937-0600\", \"timeSpent\": \"3h 20m\", \"timeSpentSeconds\": 12000, \"id\": \"1234\"}"

So I replaced my 'data' with this (adding in my own values). And that gives me the 400 Bad request error. I would be eternally grateful for suggestions as to what I can do to rectify this. I am sure I am doing something silly here but cannot seem to find it / figure it out.

Thanking you!

来源:https://stackoverflow.com/questions/31007709/400-500-error-adding-worklog-in-jira-rest-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!