Swift4,Alamofire在发布后“访问被拒绝”

时间:2018-08-24 15:43:57

标签: ios xcode swift4

在此之前,我想说我是swift和ios开发的新手。

我正在尝试使用cocoapod alamofire向服务器发布信息。 在具有身份验证的所有必要要求并使用下面的代码(即“操作”按钮)之后。因此,单击按钮后,我希望发送数据。

@IBAction func deliveryFormSubmit(_ sender: Any) {


    let query = "auth"
    let url = GlobalVar.API_URL + query

    let headers: HTTPHeaders = [
        "Content-Type": "application/json",
        "Source": "#######"
    ]
    let data: Parameters = [
        "waybill" : 102,
        "city": "test",
        "name": "Test",
        "external_branch": "test",
        "address": "test",
        "name_from": "test",
        "date": "test",
        "province": "test",
        "dept": "test",
        "name_to": "test",
        "created_user": "test",
        "trans_num": "test",
        "modified_datetime": "test",
        "comments": "comments",
        "mail_type": "test",
        "received_name": "test",
        "modified_user": "test",
        "created_datetime": "Test",
        "country": "canada"
    ]
    Alamofire.request(url, method: .post, parameters: data, encoding: JSONEncoding.default, headers: headers)
        .responseString { response in
            print(response)

            var errormessage: String = "Error"

            if response.result.isFailure {
                if let error = response.result.error as? AFError, error.responseCode == 499 {
                    //INVALID SESSION RESPONSE
                    print("INVALID SESSION RESPONSE")
                    errormessage = "** INVALID SESSION RESPONSE **"
                } else {
                    //NETWORK FAILURE
                    print("NO NETWORK")
                    errormessage = "Cannot connect to Workforce, please try again later."
                }

                GlobalVar.isLoggedIn = false
                SCLAlertView().showError(GlobalVar.appNameLabel, subTitle: errormessage)
            }
            if let result = response.result.value {
                let jsonData = result as Any
                let json = JSON(jsonData)
                let auth = json["auth"].stringValue
                if (auth == "success") {
                    print("success")
                }
            }
    }

}

我在终端收到一条消息:

SUCCESS: {"error":"Access Denied"}

关于发布的信息为何被拒绝,我没有收到任何其他信息。

我已经检查了凭据和所有其他身份验证,并且一切正确。

我缺少明显的东西吗?

谢谢!

0 个答案:

没有答案