我正在使用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数组,但是当发送到服务器时,它表示不存在索引数组

服务器在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 []数组

任何帮助深表感谢。

最佳答案

因为是导致问题的原因是您的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可能会很好地解决您的问题。

10-06 02:02