Search code examples
iosobjective-cswiftafnetworking-2

Getting 404 on PATCH Request from AFNetworking (iOS) but 200 from Browser


I'm trying to do a PATCH request to a server but I always get 404 in my petition, however in the browser I get 200. As far as I can see the PATCH request with AFNetworking is not attaching my parameters to the URL and that's causing the error. Any idea why?. Is there something that I am missing? Here is the petition as I'm doing it:

let params = ["token": token, "id": id]  
let requestSerializer = AFJSONRequestSerializer()
let responseSerializer = AFJSONResponseSerializer(readingOptions:
                NSJSONReadingOptions.AllowFragments)
let baseURL = NSURL(string: GlobalConstants.WebServiceURL.base)
let httpRequestOperationManager = AFHTTPRequestOperationManager(baseURL: baseURL)

requestSerializer.setValue("application/json", forHTTPHeaderField: "Content-Type")

requestSerializer.timeoutInterval = NSTimeInterval(GlobalConstants.httpRequestTimeout)

httpRequestOperationManager!.requestSerializer = requestSerializer
httpRequestOperationManager!.responseSerializer = responseSerializer

httpRequestOperationManager.PATCH(url,
                                parameters: params,
                                success: { (operation: AFHTTPRequestOperation!, responseObject: AnyObject!) in

                                    onSuccess()

                                }, failure: { (operation: AFHTTPRequestOperation!, error: NSError!) in

                                    onFailure(error)

                            })

Solution

  • instead:

    httpRequestOperationManager.PATCH(...)
    

    try use:

    httpRequestOperationManager.GET(...)