I use standard URLSession to send a POST
request
URLSession(configuration: .default).dataTask(with: urlRequest)
but it returns a backend error
{
"http_code" = 404;
message = "Not Found";
}
I told a backend guy about it and he said that the request fails because the server somehow receives my request as GET
136.*.*.228 - - [02/Dec/2019:09:01:48 +0000] "GET /api/v1/subscribe HTTP/2.0" 404 49 "-" "App/16 CFNetwork/1120 Darwin/18.7.0" "-"
but print(urlRequest.httpMethod)
right before dataTask(with: urlRequest)
shows "POST"
A request from the Terminal works just fine
curl -X POST "https://website.com/api/v1/subscribe" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"email\": \"email@mail.com\", \"message\": \"hey\", \"name\": \"John Doe\", \"tag\": \"preorder\"}"
EDIT: Don't want to be rude, but did anyone try reading the post before answering with standard phrases? I know what 404 means. I know that the path is correct.
I removed "www." from the request and the error changed to the right one — 400 (instead of 404). It appeared that we had a redirect from www.sitename.com to sitename.com and I didn't know about it.
Posting it in case anybody encounters the same unexpected problem.