Я использую спокойный сервис WCF в виде JSON типа "GET". Я хочу знать, как использовать службу типа "POST", чтобы я мог отправлять большие объемы данных.
Вот мой код для типа "GET":
NSURL *jsonURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.xxx.com /coffeeiphone/Service.svc/maintransactioninsert/%@/%@/%@",stockid,[format stringFromDate:selected],[quantity text], nil]];
NSString *jsonData = [[NSString alloc] initWithContentsOfURL:jsonURL];
Ответ 1 · рейтинг 1 · Angela Navarro
Для GET это работает, чтобы просто получить содержимое URL-адреса, как вы сделали выше. Для POST вам нужно будет создать NSMutableURLRequest.
NSURL *theUrl = [NSURL URLWithString:@"yourURL"];
NSMutableURLRequest *theRequest = [[NSMutableURLRequest alloc] initWithURL:theUrl];
[theRequest setHTTPMethod:@"POST"];
//set the body of your request:
[theRequest setHTTPBody: //request here];
//get your response:
NSData *response = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:nil error:nil];
Чтобы создать JSON, попробуйте взглянуть на json-framework. https://github.com/stig/json-framework/