Search code examples
xcodeswiftnsurlrequesthttp-method

HTTPMethod in NSURLRequest


I'm trying to set the http method as POST but Xcode says it's a get-only property.

I'm doing it this way:

 request.HTTPMethod = "POST"

Apple Documentation says I have to declare the httpMethod this way:

var httpMethod:String? {get}

But I don't understand how it's to be to work fine.


Solution

  • Default behavior of NSURLRequest is immutable. If you want to be able to edit something in the request, you need to use NSMutableURLRequest. Then you can set the .HTTPMethod as you did.