问题描述
我正在尝试使用c#和REST API在JIRA云中创建问题, 我收到400错误(错误的请求),我不知道自己在做错什么!
这是我的功能
public static string PostJsonRequest(string endpoint,string userid,string password,string json)
{
// Create string to hold JSON response
string jsonResponse = string.Empty;
using (var client = new WebClient())
{
try
{
client.Encoding = System.Text.Encoding.UTF8;
client.Headers.Set("Authorization","Basic " + GetEncodedCredentials(userid,password));
client.Headers.Add("Content-Type: application/json");
client.Headers.Add("Accept","application/json");
var uri = new Uri(endpoint);
var response = client.UploadString(uri,"POST",json);
jsonResponse = response;
}
catch (WebException ex)
{
// Http Error
if (ex.Status == WebExceptionStatus.ProtocolError)
{
HttpWebResponse wrsp = (HttpWebResponse)ex.Response;
var statusCode = (int)wrsp.StatusCode;
var msg = wrsp.StatusDescription;
// throw new SmtpException(statusCode,msg);
}
else
{
// throw new HttpException(500,ex.Message);
}
}
}
return jsonResponse;
}
这是我的JSON
string json = @"{
'fields':
{
'project':
{
'key':'IS'
},'summary':'REST Test','issuetype':
{
'name':'Bug'
},}
}”;
string Url = "https://XXXXXX.atlassian.net/rest/api/2/issue/";
关于我在做什么错的任何想法吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)