如何在iphone中使用post-type restful wcf服务?

如何在iphone中使用post-type restful wcf服务?,iphone,objective-c,wcf,rest,post,Iphone,Objective C,Wcf,Rest,Post,我正在使用类型为“GET”的JSON形式的restful WCF服务。 我想知道如何使用“POST”类型的服务,以便发送大量数据 这是我输入“GET”的代码: NSURL *jsonURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.xxx.com /coffeeiphone/Service.svc/maintransactioninsert/%@/%@/%@",stockid,[format stringFr

我正在使用类型为“GET”的JSON形式的restful WCF服务。 我想知道如何使用“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];   

对于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框架

可能重复的