[英]JSON method POST with Alamofire and SwiftyJSON
I'm trying to send data (parameters) into my local backend:我正在尝试将数据(参数)发送到我的本地后端:
Here is some code:这是一些代码:
Swift: 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-Table with needed attributes:具有所需属性的 SQL 表:
CREATE TABLE public.employee
(
id SERIAL PRIMARY KEY,
firstName CHARACTER VARYING(30),
tabel CHARACTER VARYING(30),
age INTEGER,
organization CHARACTER VARYING(30)
);
but only second parameter AGE sends into backend.但只有第二个参数AGE发送到后端。 Parameter FIRSTNAME is Null:(
参数FIRSTNAME是 Null:(
Thanks in advance for any suggestions!在此先感谢您的任何建议!
It was the alias on the Application Server Side:它是应用服务器端的别名:
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')
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.