带有Alamofire和SwiftyJSON的JSON方法POST

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

我正在尝试将数据(参数)发送到本地后端:

这里是一些代码:

Swift:

let parameters: Parameters = ["firstname": "User", "age": "33"]

        NetworkManager.sharedInstance.manager.request(localServer,
                                                      method: .post,
                                                      parameters: parameters,
                                                      encoding: JSONEncoding.default,
                                                      headers: [:]).responseString { response in
            switch response.result {
                case .success(let value):
                    let json = JSON(value)
                    print("JSON: \(json)")
                case .failure(let error):
                    print(error)
            }
        }

具有所需属性的SQL表:

CREATE TABLE public.employee 
(
    id SERIAL PRIMARY KEY,
    firstName CHARACTER VARYING(30),
    tabel CHARACTER VARYING(30),
    age INTEGER,
    organization CHARACTER VARYING(30)
);

但只有第二个参数AGE发送到后端。参数FIRSTNAME为Null:(

提前感谢您的任何建议!

ios json alamofire swift5 swifty-json
1个回答
0
投票

它是应用程序服务器端的别名

api.post("/employee/req", jsonParser, function(request, response){
        let { name, age } = request.body;
        pool.query('insert into public.employee (firstname, age) values ($1, $2)', [name, age], (error, results) => {
            if (error) {
                throw error
            }
            response.status(201).send('User added')
        })
© www.soinside.com 2019 - 2024. All rights reserved.