我正在尝试将数据(参数)发送到本地后端:
这里是一些代码:
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:(
提前感谢您的任何建议!
它是应用程序服务器端的别名:
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')
})