Alamofire invalid value around character 0

前端 未结 11 1960
忘了有多久
忘了有多久 2020-11-29 02:26
Alamofire.request(.GET, \"url\").authenticate(user: \"\", password: \"\").responseJSON() {
    (request, response, json, error) in
    println(error)
    println(jso         


        
11条回答
  •  一整个雨季
    2020-11-29 03:18

    The same issue happened to me and it actually ended up being a server issue since the content type wasn't set.

    Adding

    .validate(contentType: ["application/json"])
    

    To the request chain solved it for me

    Alamofire.request(.GET, "url")
            .validate(contentType: ["application/json"])
            .authenticate(user: "", password: "")
            .responseJSON() { response in
                switch response.result {
                case .Success:
                    print("It worked!")
                    print(response.result.value)
                case .Failure(let error):
                    print(error)
                }
            }
    

提交回复
热议问题