【发布时间】:2016-11-16 20:29:37
【问题描述】:
我正在使用我的 json 数据向 JIRA 发送 POST 请求以创建项目,但我无法在 JIRA 中创建项目,我试图从 Fiddler 中查看错误,但出现以下错误。我正在使用java。
我正在从以下代码发布 json 数据,请指出我错了什么以及哪里错了?
public static void createTicket()throws Exception{
HttpClient client = new DefaultHttpClient();
try {
HttpPost post = new HttpPost(webPage);
Base64 b = new Base64();
String encoding = b.encodeAsString(new String("" + name + ":" + password + "").getBytes());
post.addHeader("Authorization","Basic "+encoding);
System.out.println(post.toString());
StringEntity params =new StringEntity("{'fields':{'project':{'key':'LCH-12'},'summary':'Sample issue','description':'Creating an issue via REST API','issuetype':{'name':'Bug'}}}");
post.setHeader("Content-type", "application/json");
post.setEntity(params);
HttpResponse httpResponse = client.execute(post);
System.out.println(httpResponse.toString());
}
catch(Exception e)
{
System.out.println(e);
}
finally {
httpClient.getConnectionManager().shutdown(); //Deprecated
}
}
错误信息如下:
POST http://localhost:8080/rest/api/latest/issue HTTP/1.1 [内容类型:文本/纯文本;字符集=ISO-8859-1,内容长度:140,分块:假] HTTP/1.1 400 错误请求 [服务器:Apache-Coyote/1.1,X-AREQUESTID:585x38x1,X-ASEN:SEN-L8200978,Set-Cookie:JSESSIONID=2DFEB40B67B19BAFAFE81CF8A30B5A88;路径=/; HttpOnly, X-Seraph-LoginReason: OK, Set-Cookie: atlassian.xsrf.token=B6XG-UN93-PXWZ-FOQK|f80007dcf150dceaa1d5f561aab3d364a3598178|lin; Path=/, X-ASESSIONID: 5i51ds, X-AUSERNAME: vinuvish1, Cache-Control: no-cache, no-store, no-transform, X-Content-Type-Options: nosniff, Content-Type: application/json; charset=UTF-8,传输编码:分块,日期:星期四,2016 年 7 月 14 日 04:15:23 GMT,连接:关闭] org.apache.http.conn.BasicManagedEntity@4b952a2d
【问题讨论】:
-
我稍后会提供源码,请看:stackoverflow.com/a/59981597/1551368
标签: java json jira apache-httpclient-4.x jira-rest-java-api