远程服务器返回错误:(500)内部服务器错误

时间:2015-07-19 06:39:58

标签: c# .net rest jira

我试图从下面的JIRA云中获取问题:

 public List<Issue> GetIssues(
        string jql,
        List<string> fields = null,
        int startAt = 0,
        int maxResult = 50)
    {
        fields = fields ?? new List<string> { "summary", "status", "assignee" };

        SearchRequest request = new SearchRequest();
        request.Fields = fields;
        request.JQL = jql;
        request.MaxResults = maxResult;
        request.StartAt = startAt;

        string data = JsonConvert.SerializeObject(request);

这给出了数据&#34;如下:

{&#34; jql&#34;:&#34; project = CI&#34;,&#34; startAt&#34;:0,&#34; maxResults&#34;:50,&#34;字段&#34;:[&#34;总结&#34;&#34;状态&#34;&#34;受让人&#34;]}

然后,我调用下面的运行查询:

string result = runQuery(JiraResource.search, data, "POST");

//运行查询定义:

 public string runQuery(
        JiraResource resource,
        string argument = null,
        string data = null,
        string method = "GET")
    {
        string url = string.Format("{0}{1}",str_baseURL,resource.ToString()); //This is my URL : https://clientname.atlassian.net/rest/api/2/search

       // string url = string.Format("{0}{1}/", str_baseURL);
        if(argument != null) // as my argument is not null here , so my url is now below
        {

            url = string.Format("{0}{1}/",url,argument); //https://clientname.atlassian.net/rest/api/2/search{"jql":"project =               CI","startAt":0,"maxResults":50,"fields":["summary","status","assignee"]}/
        }
        HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
        request.ContentType = "application/json";
        request.Method = method;
        /*if (data != null) //for time being commented it, becoz of error
        {
            using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
            {
                writer.Write(data);
            }
        }*/
        string base64Credentials = GetEncodedCredentials();
        request.Headers.Add("Authorization", "Basic " + base64Credentials);
        HttpWebResponse response = request.GetResponse() as HttpWebResponse; //Here Im getting "Remote server returned an error(500) Internal server error"
        string result = string.Empty;
        using (StreamReader reader = new StreamReader(response.GetResponseStream()))
        { result = reader.ReadToEnd(); }

        return result;
    }

我做错了什么?请注意,我的其他方法,如&#34; GetProjects&#34;工作正常,我得到了JSON。请指导我。

2 个答案:

答案 0 :(得分:0)

如果您向Atlassian托管的服务器发出请求(就像您看到的那样),那么500内部服务器错误响应表明Atlassian结束时出现问题,而不是您的问题。我建议联系Atlassian寻求支持。

答案 1 :(得分:0)

问题已解决:我这样做了:

 string url = string.Format("{0}{1}", str_baseURL, resource.ToString());
        if (argument != null)
        {
            method = "POST";
            //url = string.Format("{0}{1}/", url, argument); 
        }
        else
        {
            method = "GET";
        }
        data = argument;
        HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
        request.ContentType = "application/json";
        request.Method = method;

“何时使用POST和何时获取”是一个问题。