Hi! I've recently decided to switch over from AlamoFire to this because it's much more Swift-ey, but I've run into the following issue:
Back in AlamoFire I'd send my request body with
Alamofire.request("https://myserver.com", method: .post, parameters: [ "title": "foo", "body": "bar", "userId": 18" ], encoding: JSONEncoding.default)
But this however, throws back a 403 forbidden. I can't seem to understand why this happens as it worked fine using AlamoFire, and if I change the body to use an encodable instead like so:
struct Test: Codable {
let title: String
let body: String
let userId: Int
}
Request {
Url("https://api.loucee.dev/register")
Method(.post)
Body(Test(title: "foo", body: "bar", userId: 18))
}
Everything works fine again! But the issue with this is that I have a lot of different requests to make in my app, and I rather not have 30 or so codables laying around...
My question is, what is causing this weird behaviour? Can I resolve it somehow?
Okay I just managed to find the solution like 20 seconds after posting this, I had to add Header.ContentType(.json) and now everything works perfectly...
Hi! I've recently decided to switch over from AlamoFire to this because it's much more Swift-ey, but I've run into the following issue:
Back in AlamoFire I'd send my request body with
Alamofire.request("https://myserver.com", method: .post, parameters: [ "title": "foo", "body": "bar", "userId": 18" ], encoding: JSONEncoding.default)
and it worked perfectly, so I rewrote this to:
But this however, throws back a 403 forbidden. I can't seem to understand why this happens as it worked fine using AlamoFire, and if I change the body to use an encodable instead like so:
Everything works fine again! But the issue with this is that I have a lot of different requests to make in my app, and I rather not have 30 or so codables laying around...
My question is, what is causing this weird behaviour? Can I resolve it somehow?