简体   繁体   English

Alamofire HTTP请求失败

[英]Alamofire HTTP requests fails

I made some HTTP requests using Alamofire. 我使用Alamofire发出了一些HTTP请求。 Some request has been succeeded and some are failed. 某些请求已成功,某些请求失败。

error is Invalid value around character 0. 错误是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 请帮我找到问题

This issue was happened because of wrong format of JSON passing. 发生此问题是因为JSON传递的格式错误。 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",
     .....
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM