使用json rest api上传附件

时间:2016-07-27 11:02:17

标签: java json jira apache-httpclient-4.x jira-rest-api

我尝试使用其余的api

将附件上传到Jira
  

我尝试过以下代码:

  String pathname ="C:\\Users\\Desktop\\Tool\\sample.png";
    BASE64Encoder base = new BASE64Encoder();
    String encoding = base.encode("test:test".getBytes());
    HttpPost postRequest = new HttpPost("https://localhost:8080/rest/api/2/issue/T-6279/attachments");
    File fileUpload = new File(pathname);
    HttpClient httpClient = HttpClientBuilder.create().build();

    postRequest.setHeader("Authorization", "Basic " + encoding);
    postRequest.setHeader("X-Atlassian-Token", "nocheck");

    MultipartEntityBuilder entity = MultipartEntityBuilder.create();
    entity.addPart("file", new FileBody(fileUpload));
    postRequest.setEntity(entity.build());



    HttpResponse response = httpClient.execute(postRequest);
    System.out.println(response);

我得到这个错误

I'm getting this Error

  

你能帮我解决这个错误吗?

0 个答案:

没有答案