具有数组参数用法的Alamofire 5 POST方法,使用速度为5

问题描述 投票:0回答:1

我正在使用带有Almofire 5.0.2的Swift 5的iOS项目。我尝试了与此类似的在线线程上建议的所有选项,但看起来我仍然缺少某些内容。

我在进行POST方法API调用时遇到了困难,其中包含一系列作为请求主体的项目。

API看起来像:

@RequestMapping(...)
SomeResponse doSomething (@RequestBody SomeRequest request) {}

[我使用的是Swift 5和Alamo fire 5.0.2版本,我尝试了上面的选项和下面的选项,但是根本没有打API(返回AFError):

let parameters: [String: Any] = [
            "block": true,
            "items": [],
            "name": "xxxxx",
            "mobile": "xxxxxxxxxx",
            "email": "[email protected]",
            "List": [["place": "london"],["place": "holand"]]

  ]

AF.request(BookingConstants.httpEndpoint, method: .post, parameters: parameters, headers: headers)
            .validate()
            .responseData { response in

}

我在Java Spring Boot API端收到此错误:

Invalid index in property path 'item[][place]'; nested exception is java.lang.NumberFormatException: For input string: ""] with root cause

java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[?:1.8.0_221]
    at java.lang.Integer.parseInt(Integer.java:592) ~[?:1.8.0_221]
    at java.lang.Integer.parseInt(Integer.java:615) ~[?:1.8.0_221]
    at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:663) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyHoldingValue(AbstractNestablePropertyAccessor.java:402) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.AbstractNestablePropertyAccessor.processKeyedProperty(AbstractNestablePropertyAccessor.java:298) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:289) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:280) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:95) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:859) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.validation.DataBinder.doBind(DataBinder.java:755) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.web.bind.WebDataBinder.doBind(WebDataBinder.java:192) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.web.bind.ServletRequestDataBinder.bind(ServletRequestDataBinder.java:106) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE

我知道我丢失了一些东西,但无法弄清楚。有人可以帮我这个忙吗?请让我知道您的意见/建议。在此先感谢

spring-boot alamofire swift5 xcode11.2 alamofire-request
1个回答
0
投票

我切换回Alamofire 4.0.1版本,并使用Alamofire上传方法来实现这一目标。

let objectAsJSON: JSON = request.toJSON()
let data: Data = try objectAsJSON.serialize()

Alamofire.upload(data, to: BookingConstants.httpEndpoint, headers: headers)
                .validate()
                .responseData { response in
        // response code logic

}
© www.soinside.com 2019 - 2024. All rights reserved.