Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languageperl
linenumberstrue
curl -D- -u fred:fred -X GET -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue/QA-31
或者
curl -D- -X GET -H "Authorization: Basic YWRtaW46YWRtaW4=" -H "X-Atlassian-Token: no-check" -H "Content-Type: application/json" "http://localhost:8080/rest/api/2/issue/QA-31"

...

Code Block
languagejava
linenumberstrue
import com.sun.jersey.api.client.*;

public class BaseClientMain {
    public static void main(String[] args) throws Exception {
        try {
            Client client = Client.create();
            WebResource webResource = client.resource("http://localhost:8080/rest/api/2/issue/QA-31");
            ClientResponse response = webResource.accept("application/json")
                    .header("Authorization", "Basic YWRtaW4lM0FhZG1pbg==")
                    .header("X-Atlassian-Token", "no-check") 
					.get(ClientResponse.class);
            String msgback = response.getEntity(String.class);
            System.out.println(msgback);
            response.close();
        } catch (UniformInterfaceException e) {
            e.printStackTrace();
        } catch (ClientHandlerException e) {
            e.printStackTrace();
        }
    }
}

说明

  • header中使用的:YWRtaW4lM0FhZG1pbg==,为admin:admin字串在经过base64位编码后的值,为{账号名}:{密码}字串(如admin:admin)在经过base64位编码后的值
  • admin:admin中间有一个冒号
  • Basic和YWRtaW46YWRtaW4=之间有一个空格