Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Alamofire httpBody在swift 5中显示500状态代码_Ios_Swift_Alamofire - Fatal编程技术网

Ios Alamofire httpBody在swift 5中显示500状态代码

Ios Alamofire httpBody在swift 5中显示500状态代码,ios,swift,alamofire,Ios,Swift,Alamofire,我用的是Alamofire 5。我已将参数放入httpbody。我已经在《邮递员》杂志上运行过了,它运行得很好。我的身体参数如下 { "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。我已将参数放入httpbody。我已经在《邮递员》杂志上运行过了,它运行得很好。我的身体参数如下

{
"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": [:]
]

您可以告诉POSTMAN在CURL中生成等效的请求,并使用Alamofire中的功能将请求打印为CURL请求(参见此处),并比较这两个代码。你会发现不同之处。但是
URLEncoding.httpBody
,作为URLEncoded?还是JSONECODED?
profile
字段是邮递员正文中的字典和AF参数中的数组。服务器是否也在告诉您为什么在响应正文中返回500?@WarrenBurton如何在配置文件字段中写入?
“配置文件”:[:]
@Larme谢谢,工作正常