Alamofire HTTP请求失败 [英] Alamofire HTTP requests fails

查看:122
本文介绍了Alamofire HTTP请求失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Alamofire发出了一些HTTP请求。

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

错误为字符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)
    }

请帮助我找到问题

推荐答案

发生此问题是因为JSON传递格式错误。然后,我将参数更改如下

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

这篇关于Alamofire HTTP请求失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆