Alamofire invalid value around character 0

前端 未结 11 1999
忘了有多久
忘了有多久 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:02

    I got the same error. But i found the solution for it.

    NOTE 1: "It is not Alarmofire error", it's bcouse of server error.

    NOTE 2: You don't need to change "responseJSON" to "responseString".

    public func fetchDataFromServerUsingXWWWFormUrlencoded(parameter:NSDictionary, completionHandler: @escaping (_ result:NSDictionary) -> Void) -> Void {
    
            let headers = ["Content-Type": "application/x-www-form-urlencoded"]
            let completeURL = "http://the_complete_url_here"
            Alamofire.request(completeURL, method: .post, parameters: (parameter as! Parameters), encoding: URLEncoding.default, headers: headers).responseJSON { response in
    
                if let JSON = response.result.value {
                    print("JSON: \(JSON)") // your JSONResponse result
                    completionHandler(JSON as! NSDictionary)
                }
                else {
                    print(response.result.error!)
                }
            }
        }
    

提交回复
热议问题