2015-05-14 205 views
2

這是我的JSON請求JSON請求使用AlamoFire

var postsEndpoint = "http://test/Search" 

let test = ["SearchCriteria":["ForeName":"jack", "Surname":"jill"]]; 


    request(.POST, postsEndpoint, parameters: test, encoding: .JSON) 
     .responseJSON { (request, response, data, error) in 
      if let anError = error 
      { 
       println("error calling POST on /posts") 
       println(error) 
      } 
      else if let data: AnyObject = data 
      { 

       let post = JSON(data) 
       println("The post is: " + post.description) 
      } 

是否有符合我的要求,因爲我收到以下錯誤的問題:

錯誤上/職位調用POST 可選(錯誤域= NSCocoaErrorDomain Code = 3840「The operation could not be completed。(Cocoa error 3840.)」(字符3周圍的值無效)。UserInfo = 0x7fdd00414c80 {NSDebugDescription =字符3周圍的值無效。})

+1

錯誤說什麼是錯的:響應你」重新獲得是無效的JSON。使用'responseString'來記錄字符串表示,看看有什麼事。 – mattt

回答

0

Late,but I找到了這個線程。

我跑進運行的Django開發服務器同樣的問題,得到了You called this URL via POST, but the URL doesn't end in a slash and you have APPEND_SLASH set. Django can't redirect to the slash URL while maintaining POST data.

附加一個斜線postsEndpoint所以它成爲...
var postsEndpoint = "http://test/Search"