尽管采用json编码,但不存在所需的参数

时间:2018-03-31 08:14:38

标签: java swift http spring-boot alamofire

我正在使用alamofire发送来自swift的http发布请求:

let url = userActivity.webpageURL

    if(url?.description.contains(UniversalLinkHandler().urlPrefix))!
    {
        let keystore = try! EtherKeystore()
        let signedOrder = UniversalLinkHandler().parseURL(url: (url?.description)!)
        let signature = signedOrder.signature.substring(from: 2)
        let parameters: Parameters = [
            "address" : keystore.recentlyUsedWallet?.address.description,
            "indices": signedOrder.order.indices,
            "v" : signature.substring(from: 128),
            "r": signature.substring(from: 0, to: 64),
            "s": signature.substring(from: 64, to: 128)
        ]
        let query = UniversalLinkHandler.paymentServer

        Alamofire.request(
                query,
                method: .post,
                parameters: parameters
        ).responseJSON {
            result in
            print(result)
        }
    }

索引在调试器中显示为普通的UInt16数组,但是当发送到服务器时它表示indices数组不存在

服务器在java中并使用springboot:

@RequestMapping(value = "/claimToken", method = RequestMethod.POST)
public ResponseEntity getAToken(@RequestParam(value="address") String address,
                                @RequestParam(value="indices") int[] indices,
                                @RequestParam(value = "v") byte v,
                                @RequestParam(value = "r") String r,
                                @RequestParam(value = "s") String s
)

第一个参数地址工作正常,但它不适用于int []数组索引

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

由于您的signedOrder.order.indices数组导致了问题,而且类型为[UInt16],我的推荐是:

let indices = signedOrder.order.indices.map(Int.init)
let parameters: Parameters = [
            "address" : keystore.recentlyUsedWallet?.address.description,
            "indices": indices,
            "v" : signature.substring(from: 128),
            "r": signature.substring(from: 0, to: 64),
            "s": signature.substring(from: 64, to: 128)
        ]

映射到Int可能很好地解决了您的问题。