开发者

How to consume post type restful wcf service in iphone?

开发者_JAVA百科I am consuming restful WCF service in the form of JSON of type 'GET'. I want to know how to consume service of type 'POST' so, that i can send large amount of data.

Here is my code for Type '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];   


For GET, it works to just get the contents of the URL like you did above. For POST, you will have to create an 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];

To construct JSON, try looking at the json-framework. https://github.com/stig/json-framework/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜