Ios 如何使用Alamofire在swift中发布请求json正文?

Ios 如何使用Alamofire在swift中发布请求json正文?,ios,swift,xcode,alamofire,Ios,Swift,Xcode,Alamofire,我需要在json正文中为我的应用程序后端发出POST请求,但响应返回失败。我假设我的json格式或编码是错误的,但我不知道问题出在哪里。我尝试了很多不同的解决方案,但都没有找到一个有效的。有人能看到我的代码的哪一部分是导致失败的原因吗 let headers: HTTPHeaders = [ "accept": "application/json", "content-type": "application/json", "authorization": self.aut

我需要在json正文中为我的应用程序后端发出POST请求,但响应返回失败。我假设我的json格式或编码是错误的,但我不知道问题出在哪里。我尝试了很多不同的解决方案,但都没有找到一个有效的。有人能看到我的代码的哪一部分是导致失败的原因吗

let headers: HTTPHeaders = [
    "accept": "application/json",
    "content-type": "application/json",
    "authorization": self.authValue,
    "x-iyzi-rnd": self.randomString,
    "cache-control": "no-cache"
]


let parameters: [String: Any] = [


        "price": "1.0",
        "paidPrice": "1.1",
        "paymentChannel": "mobile_ios",
        "paymentCard": [
            "cardHolderName": "card_name",
            "cardNumber": "card_no",
            "expireYear": "2030",
            "expireMonth": "09",
            "cvc": "123"
        ],
        "buyer": [
            "id": "123123123",
            "name": "john",
            "surname": "doe",
            "identityNumber": "12345678902",
            "email": "johndoe@gmail.com",
            "registrationAddress": "nidakulegöztepemerdivenköymahborasokno1",
            "city": "istanbul",
            "country": "turkey",
            "ip": "192.168.1.82"
        ],
        "shippingAddress": [
            "address": "nidakulegöztepemerdivenköymahborasokno1",
            "contactName": "janedoe",
            "city": "istanbul",
            "country": "turkey"
        ],
        "billingAddress": [
            "address": "nidakulegöztepemerdivenköymahborasokno1",
            "contactName": "janedoe",
            "city": "istanbul",
            "country": "turkey"
        ],
        "basketItems": [
            [
                "id": "321",
                "price": "0.3",
                "name": "binocular",
                "category1": "collectibles",
                "itemType": "physical"
            ],
            [
                "id": "432",
                "price": "0.5",
                "name": "gamecode",
                "category1": "game",
                "itemType": "virtual"
            ],
            [
                "id": "543",
                "price": "0.2",
                "name": "usb",
                "category1": "electronics",
                "itemType": "physical"
            ]
        ],
        "currency": "try"


]


Alamofire.request("https://api.iyzipay.com/payment/auth", method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: headers).responseJSON(completionHandler: {
    response in response

    let jsonResponse = response.result.value as! NSDictionary
    print(jsonResponse)



})

发布请求json正文有什么不同的方法吗

尽量不要修改
接受
内容类型
缓存控制
标题,让Alamofire决定这些标题。只需发送
授权
和您需要的一切。当然,授权的标题也总是大写的。请先试用POSTMAN,然后检查。@Aditya我已经试过了,它给出了相同的错误。您试用过POSTMAN和相同的标题吗?如果它给你同样的错误,这是后端问题,而不是前端问题。你的代码似乎是正确的。让你的后端先和邮递员一起工作,当这种情况发生时,回到你的前端代码。