ios - 使用 JIRA API 接收项目列表

标签 ios swift rest jira-rest-api

我想为 iOS 制作简单的 JIRA 助手,但无法弄清楚为什么 API 调用返回空数组。

例如,使用此代码我尝试获取项目列表:

let request = NSMutableURLRequest(URL: "http://myjira.atlassian.net/rest/api/2/project".URL!)
    request.addValue("Basic " + emailAndPasswordAsb64String, forHTTPHeaderField: "Authorization")
    request.addValue("application/json", forHTTPHeaderField: "Content-Type")
    request.HTTPMethod = "GET"

let session = NSURLSession.sharedSession()

session.dataTaskWithRequest(request) { (data, response, error) -> Void in
    guard let data = data, responseString = NSString(data: data, encoding: NSUTF8StringEncoding) as? String where !responseString.isEmpty else {
        print("No valid response!", appendNewline: true)
        return
    }

    print("Response: " + responseString, appendNewline: true)

}.resume()

但是得到这个:Response: []

我还尝试使用其他一些API,例如api/2/dashboard ,但收到了这个: Response: {"startAt":0,"maxResults":20,"total":0,"dashboards":[]}

使用api/2/myself我收到这个: Response: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><status><status-code>401</status-code><message>Client must be authenticated to access this resource.</message></status>

也许我错过了一些东西,项目可能是不可见的?但对于基本授权,我使用管理员登录名和密码。

最佳答案

终于明白了!

我犯了两个错误:

  1. http 是错误的,https 是正确的!
  2. emailAndPasswordAsb64String 是使用电子邮件和密码创建的,这是错误的!用户应该输入用户名而不是电子邮件!对于管理员帐户,默认用户名是 admin

希望这会对某人有所帮助!

关于ios - 使用 JIRA API 接收项目列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31835966/

相关文章:

ios - Cocos2d 在我使用 UIScrollView 时停止

iphone - Facebook 提及标签不起作用

ios - 访问前一个 viewController 元素及其标签

ios - 如何在 Swift 中从不同的 ViewController 重新加载 TableView 中的数据

REST:PUT 以及如何处理部分实体

jquery - 如何调整页眉以在 iOS 6 和 iOS 7 中正常工作?

ios - 将 UITableViewCell 的高度调整为 UITextView 的高度

ios - 如何在 swift4.2 中将 Realm 文件与我的应用程序捆绑在一起?

java - 使用rest来通信两个基于表单的springboot应用程序

regex - Jax-RS 重载方法/路径执行顺序