Alamofire: UserInfo={NSDebugDescription=Invalid value around character 0.

Created on 28 May 2016  路  7Comments  路  Source: Alamofire/Alamofire

Hi,

I'm trying to send a .GET with a custom header, but I'm getting this error

FAILURE: Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.}

the code I'm using is the following:

let headers = ["token": "\(token)", "Accept": "application/json"] let request = Alamofire.request(.GET, "localhost/api", headers : headers).responseJSON(completionHandler: { (response) -> Void in if let JSON = response.result.value { print(response) } } else { print (response) } })

I tried to make the request using the postman and it went fine.

Most helpful comment

@kuantico This error occurs when you use .responseJSON() and API returns invalid JSON string. Try to use .responseString() and you will see what's coming from API. It's server-side problem.

All 7 comments

I figure it out. Thanks (:

how?

I don't remember exactly, but problem occurred because I wasn't using the web service api properly. I was sending data in the wrong format or something like that.

@kuantico This error occurs when you use .responseJSON() and API returns invalid JSON string. Try to use .responseString() and you will see what's coming from API. It's server-side problem.

used responseString() but now respose is "Unauthorized" why?

When I tried .responseString(), the response is just
==> SUCCESS: !DOCTYPE html>

i face this problem then i change it to responseString but the result = [Result]: SUCCESS: Error Input Data

Was this page helpful?
0 / 5 - 0 ratings