I'm currently submitting a json request to the following .NET MVC action
[AcceptVerbs(HttpVerbs.Post)]
public JsonResult Signup(FormCollection collection)
{
However the collection is empty for some reason. I know that the data is being sent because if I change it to
[AcceptVerbs(HttpVerbs.Post)]
public JsonResult Signup(String username, String email, String password)
{
I'm using form collection because it allows me to have optional parameters for the method. In the future I might not have username i might have name (for example) but I can't have the old url break
The request is coming from an iOS app in the form of a NSMutableURLRequest. Am I missing something or do I have to use the second option and create a different method for when I add new parameters/ create a separate version of the .NET MVC app for when I release new app updates.
So yeah its because I'm posting the data like this
NSMutableDictionary *sendData = [[NSMutableDictionary alloc] init];
[sendData setValue:self.usernameTxt.text forKey:@"username"];
[sendData setValue:self.emailTxt.text forKey:@"email"];
[sendData setValue:self.deviceToken forKey:@"device_token"];
//verify account details and retrieve the API Key
responseData = [NSMutableData data];
NSString *stringUrl = kAppRequestUrl;
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[stringUrl stringByAppendingString:@"/SomePath"]]];
[request setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody: [sendData JSONData]];