2011-05-21 19 views
0

我正在以'GET'類型的JSON的形式使用安寧的WCF服務。 我想知道如何使用'POST'類型的服務,以便我可以發送大量數據。如何在iphone中使用post type restful wcf服務?

這裏是我的類型「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]; 
+0

[POST REST-Web-Service Call for iPhone application]的可能重複(http://stackoverflow.com/questions/2568426/post-rest-web-service-call-for-iphone-application) – 2011-05-21 05:58:25

+0

i想要用於json格式 – user746909 2011-05-21 07:56:42

回答

1

對於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框架。 https://github.com/stig/json-framework/