NSUrlConnection を使用して、iOS アプリケーションで安らかな Web サービスを試みています。以下のコードを使用して json 文字列をフォーマットし、安らかな Web サービスに送信しています。しかし、connectionReceiveResponse: メソッドで '415(unsupported media type)' 応答を取得しています。ここでどこが間違っているのか教えてください。
NSURL *urlLoginAuthentication= [NSURL URLWithString:@" http://www.loginService/mp/api "];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:urlLoginAuthentication];
[request setHTTPMethod:@"POST"];
NSMutableDictionary *jsonDict = [[NSMutableDictionary alloc] initWithObjects:[NSArray arrayWithObjects:self.txtUserName.text, self.txtPassWord.text,nil] forKeys:[NSArray arrayWithObjects:@"username",@"password", nil]];
NSLog(@"Dict: %@",jsonDict);
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict options:kNilOptions error:nil];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSLog(@"JSON String: %@",jsonString);
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"contentType"];
[request setValue:@"json" forHTTPHeaderField:@"dataType"];
[request setValue:[NSString stringWithFormat:@"%d", [jsonData length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody: jsonData];
NSLog(@"jsonData: %@",jsonData);
self.connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];