title: Formatting HTTP request with Alamofire "format=json&body="
body: <p>I'm trying to send an api request that needs to look like this:</p>
  
  <p><a href="https://api.gibbly.com/1/device?format=json&amp;body=" rel="nofollow noreferrer">https://api.gibbly.com/1/device?format=json&amp;body=</a>{"selection"={"selectionType":"registered","selectionMatch":"","includeRuntime":true}}</p>
  
  <p>However, when I use the code below, I get an error.  In the [RESULT] segment of the response, I get the following:</p>
  
  <pre><code>[RESULT] FAILURE: responseSerializationFailed(reason: Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(error: Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.}))
  </code></pre>
  
  <p>I've tried the request using Postman and it works fine so I think the issue is caused by the code. </p>
  
  <p>Based on the first "print" statement in the code, the HTTP body seems correct:</p>
  
  <pre><code>Optional({"selection":{"selectionType":"registered","selectionMatch":"","includeSettings":true}})
  </code></pre>
  
  <p>The only thing I can think of is that Alamofire isn't adding "format=json&amp;body=" into the request but I can't figure out how to see whether that's the case.  Any help would be appreciated.</p>
  
  <pre><code>
          let headers: HTTPHeaders = [
              "Authorization": "Bearer adsf023494axadf32342",
              "Content-Type": "text/json"
          ]
  
          let parameters: [String: Any] = [
              "selection":[
                  "selectionType":"registered",
                  "selectionMatch":"",
                  "includeSettings":true
              ]
          ]
  
          Alamofire.request(url!, method: .get, parameters: parameters, encoding: JSONEncoding.default, headers: headers).responseJSON {
              response in
  print(NSString(data: (response.request?.httpBody)!, encoding: String.Encoding.utf8.rawValue))
              print(response)
          }
  </code></pre>