发生未处理的错误:responseSerializationFailed(原因:Alamofire.AFError.ResponseSerializationFailureReason.inputDataNilOrZeroLength)

时间:2020-10-28 08:17:50

标签: ios swift alamofire

我正在实施登录注册,但是Alamofire出现错误

func post(_ api: PiPiAPI, param: [String:Any]) -> httpResult {
    print(baseURL + api.path())
    print(param)
    return requestData(.post, baseURL + api.path(),
                       parameters: param,
                       encoding: JSONEncoding.prettyPrinted,
                       headers: api.header())
}

但是,我使用上面的Post功能实现了登录,但是当实现成员注册时,不会发送身份验证电子邮件。

func sendAuthCode(_ email: String) -> Observable<networkingResult> {
    httpClient.post(.postAuthCode, param: ["email": email])
        .map { response, data -> networkingResult in
            print(response.statusCode)
        switch response.statusCode {
        case 200:
            print("send email")
            return .ok
        case 409:
            print("Dd")
            return .conflict
        default:
            print(response.statusCode)
            return .fault
        }
    }
}

并且也不会打印response.statusCode。

Unhandled error happened: responseSerializationFailed(reason: Alamofire.AFError.ResponseSerializationFailureReason.inputDataNilOrZeroLength)

如何解决此错误?

0 个答案:

没有答案