反正有在不使用键值的情况下在TRON中执行request.parameters
我尝试使用以下参数和标头从邮递员那里击球,效果很好,但是当我尝试使用TRON进行实现时,后端会收到空帖。
在我不使用let data = JSON(form).rawString()
之前
我怀疑如果不使用它,可能不会返回json形式,
因为TRON参数包含parameters: [String: Any]
因此,当我尝试实现它时,返回错误Cannot assign value of type 'String?' to type '[String : Any]'
class Controller {
let auth = "http://dummy.com"
func callTron(){
let form : [String: Any] = [
"name" : "S",
"id" : "1"
]
let request = NewBaseRequest()
request.performNew(tron: auth, form: form, endPoint: "api", completion: { //call NewBaseRequest
if request.isSuccess {
//success
}else{
//failed
}
})
}
}
class NewBaseRequest {
let authHtml = ["Content-Type : application/json", "x-token : 123"]
var data = JSON.null
func performNew(tron: TRON, form: [String: Any], endPoint: String, completion: (() -> Swift.Void)? = nil) {
let data = JSON(form).rawString()
let request: APIRequest<BaseNewResponse, JSONError> = tron.request(endPoint)
request.method = .post
request.headers = authHtml
request.parameters = data //return error Cannot assign value of type 'String?' to type '[String : Any]'
print(request.paramaters)
request.perform(withSuccess: { (response) in
//success
completion!()
}) { (err) in
//failed
completion!()
}
}
}
我尝试打印(request.parameters)有一个值["name": "s", "id": "1"]
我不确定是什么原因导致此过程为空
编辑
这是参数的样子:
Header :
Content-Type : application/json
x-token : 123
Body :
{
"name" : "encrypt(uuid)",
"id": "1.0",
}