Alamofire HTTP requests fails

六月ゝ 毕业季﹏ 提交于 2020-01-05 21:09:12

问题


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:


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",
     .....
    }
}


来源:https://stackoverflow.com/questions/33699900/alamofire-http-requests-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!