【问题标题】:Swift Alamofire response to .jspSwift Alamofire 对 .jsp 的响应
【发布时间】:2016-07-27 09:38:32
【问题描述】:

我想登录this link 我的代码是这样的

override func viewDidLoad() {
    super.viewDidLoad()

    let username = "14-032"
    let password = "choi3704"
    let loginParameters = ["id": username as String, "pwd": password as String]

    Alamofire.request(.POST, "http://students.ksa.hs.kr/scmanager/stuweb/index.jsp", parameters: loginParameters, encoding: .JSON).responseJSON{ response in switch response.result {
    case .Success(let JSON):
        let response = JSON as! NSDictionary
        print(response.objectForKey("type"))
    case .Failure(let error):
        print("Request failed with error, \(error)")
        }
    }
}

我得到了

请求失败并出现错误,错误域=NSCocoaErrorDomain Code=3840“字符 8 周围的值无效。” UserInfo={NSDebugDescription=字符 8 周围的值无效。}

我该如何解决这个问题?

【问题讨论】:

    标签: swift jsp swift2 alamofire


    【解决方案1】:

    查看我的other answer,了解如何在网站上寻找信息。您没有使用正确的 URL,也没有使用 encoding: .JSON

    Alamofire.request(.POST, "http://students.ksa.hs.kr/scmanager/stuweb/loginProc.jsp", parameters: loginParameters)
        .responseJSON{ response in
            switch response.result {
            case .Success(let JSON):
                let response = JSON as! NSDictionary
                print(response.objectForKey("type"))
            case .Failure(let error):
                print("Request failed with error, \(error)")
                }
        }
    

    其他几点说明:

    • 请不要将真实的用户名和密码发布到 StackOverflow。有些机器人会扫描这些。
    • 您的学校使用不安全 HTTP 作为登录站点。他们要求被黑客入侵。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-18
      • 2021-07-22
      • 1970-01-01
      • 2019-03-05
      • 2021-09-17
      • 1970-01-01
      相关资源
      最近更新 更多