Search code examples
iosmacoscocoansurlrequest

NSString constants for NSURLRequest HTTPMethod property?


Does Foundation have NSString constants for the supported HTTPMethod values (eg for GET, POST, etc)?

Searched the NSURLRequest docs, but couldn't find anything.


Solution

  • To my knowledge, NSURLRequest doesn't have any constants for HTTP method types. You could, however, define your own and use them elsewhere. Something like this:

    //Somewhere
    #define setPOST(request) [request setHTTPMethod:@"GET"]
    
    //...later in code
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    setPOST(request);
    

    I would also highly recommend using AFNetworking. With that library, you can easily do things like:

    [connectionMgr POST:url parameters:submitDict success:nil failure:nil]; //Obviously bare-bones, you'd need to fill in the parameters and blocks