我想登录 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)")
}
}
}
我得到了
Request failed with error, Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 8." UserInfo={NSDebugDescription=Invalid value around character 8.}
如何解决这个问题?
最佳答案
查看我的other answer了解如何搜索网站以获取信息。您没有使用正确的 URL,也没有使用编码:.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 作为登录网站。他们要求被黑客攻击。
关于快速 Alamofire 响应 .jsp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38609214/