AlamoFire POST将不允许获取'错误形式DRF服务器

时间:2018-03-04 08:15:00

标签: ios django django-rest-framework alamofire swift4

二手技术

  • Django 2与Django Rest Framework(Drf)
  • JWT for authentication
  • 式IO / Swift4 / Alamofire

这里的问题。 django将收到Alamofire的POST请求作为GET请求。

iOS / swift4代码。

static func getToken (){
    let username = "root"
    let password = "DAMnShEIsSoHo1!t"

    let parameters: [String: Any] = [
        "username" : username,
        "password" : password,
    ]
    let url = ApiController.baseServerUrl + "api-token-auth"
    print("URL :: \(url)")
    Alamofire.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.default)
        .responseJSON { response in
            print("RESPONSE :: \(response)")
    }

}

从iOS登录

  

RESPONSE :: SUCCESS:{       detail =" Method \" GET \"不允许。&#34 ;; }

从django服务器登录

  

my.ip.address - - [04 / Mar / 2018:07:55:32 +0000]" GET / api-token-auth / HTTP / 1.1" 405 40" - " " Foodle / 0.0.1(com.domain.Appname; build:2;   iOS 11.2.0)Alamofire / 4.6.0"

DRF web console

enter image description here

enter image description here

我该怎么办?

PS。它适用于PostMan,DRF Web控制台和CURL

1 个答案:

答案 0 :(得分:0)

始终在端点末尾添加/