gpt4 book ai didi

ios - Alamofire httpBody 在 swift 5 中显示 500 statusCode

转载 作者:行者123 更新时间:2023-11-28 23:21:50 24 4
gpt4 key购买 nike

我用的是Alamofire 5,我把参数放到了httpbody。我已经在 Postman 中运行它,并且运行良好。我的 body 参数如下。

{
"user_id": "user_id",
"username": "user_name",
"password": "pass",
"token": "",
"type_id": 100,
"country_id": 1,
"language_id": 1,
"customer_id": 1,
"parent_user_id": "",
"profile": {}
}

我使用下面的代码使用 Alamofire 5 发出请求。这是代码:

func change_password() {

let headers: HTTPHeaders = [
"Content-Type": "application/json",
"YumaSession": Global_Variable.globalValue.session_id
]
let parameters:Parameters = [
"user_id": "user_id",
"username": "username",
"password": txtPassword.text!,
"token": "",
"type_id": 100,
"country_id": 1,
"language_id": 1,
"customer_id": 1,
"parent_user_id": "",
"profile": []
]

AF.request( url,method: .put,parameters: parameters,encoding: URLEncoding.httpBody,headers: headers).responseJSON{ response in

switch response.result {
case .success(let responseData):
print("responseData-->",response.response!.statusCode)
case .failure(let error):
print("error--->",error)
}
}
}

以上代码返回 500 状态码。代码上面有什么问题?

最佳答案

parameters.profile 是用数组文字而不是字典文字定义的。固定代码如下。

let parameters:Parameters = [
"user_id": "user_id",
"username": "username",
"password": txtPassword.text!,
"token": "",
"type_id": 100,
"country_id": 1,
"language_id": 1,
"customer_id": 1,
"parent_user_id": "",
"profile": [:]
]

关于ios - Alamofire httpBody 在 swift 5 中显示 500 statusCode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59546152/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com