Alamofire HTTP requests fails

2019-08-09 09:36发布

I made some HTTP requests using Alamofire. Some request has been succeeded and some are failed.

error is Invalid value around character 0.

Failed request gave me above error.

bellow i have mentioned a sample code which failed.

let parameters = ["amount": ["10"], "payment_method": ["paypal"], "date": ["2015-11-25"], "details": ["Payment description"]]

    let headers = [
        "Accept": "*/*",
        "Content-Type": "application/json"
    ]

    let url = "https://livetest.somedomain.com/api/invs/LAT1j5da99PdPg/payments?auth_token=pbtTEPNki3hUhGBuPX3d"

    Alamofire.request(.POST, url, parameters: parameters, encoding: .JSON, headers: headers)
        .responseJSON { response in
            let results = response.result
            print(results)
            print(response.debugDescription)
    }

Please help me to find the issue

1条回答
Juvenile、少年°
2楼-- · 2019-08-09 10:14

This issue was happened because of wrong format of JSON passing. Then i changed the parameter as follows

let parameters = ["payment":["amount": "100" , "payment_method": "check", "date": "2015-11-25", "details": "Payment description dimuth Lasantha"]]

Now it passes the correct format which is

{
payment: {
    "amount" : "100",
    "payment_method" : "check",
     .....
    }
}
查看更多
登录 后发表回答