博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Cocoa 通过http请求调用WCF服务

Posted on 2013-10-17 17:31  勿以己悲  阅读(379)  评论(0)    收藏  举报




以 Get的方式传递Http请求:
 
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];   
  

 



以 POST的方式传递Http请求:

 

 

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];