I am new to iphone technology , can any one help , i want to send a JSON DATA using POST method to server.
can any one help me by giving some simple sample application
I am new to iphone technology , can any one help , i want to send a JSON DATA using POST method to server.
can any one help me by giving some simple sample application
You have to make use of NSUrlConnection
for this job.
SO already has a well explained Question
You have to set your JSON data as http Body in the NSUrlRequest
There are also other kits such as ASIHTTPRequest (abandoned but used widely now also),RestKit etc.
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:requestUrlString]];
NSMutableDictionary *dict1 =[[NSMutableDictionary alloc] init];
if ([m_ProductInfoDictonary objectForKey:@"TOKEN"] != nil) {
[dict1 setObject:[mAppDelegate.m_ProductDictonary objectForKey:@"TOKEN"] forKey:@"token"];
NSMutableDictionary *dict2 =[[NSMutableDictionary alloc] init];
[dict2 setObject:[mAppDelegate.m_ProductDictonary objectForKey:@"PRODUCTNAME" ] forKey:@"title"];
[dict2 setObject:[mAppDelegate.m_ProductDictonary objectForKey:@"DESCRIPTION" ] forKey:@"description"];
[dict2 setObject:[mAppDelegate.m_ProductDictonary objectForKey:@"PRODUCTPRICE" ] forKey:@"price"];
[dict2 setObject:[mAppDelegate.m_ProductDictonary objectForKey:@"ZIPCODE" ]forKey:@"zipcode"];
NSMutableDictionary *dict =[[NSMutableDictionary alloc] init];
[dict setObject:dict2 forKey:@"item"];
[dict setObject:dict1 forKey:@"user"];
//[dict setObject:dict3 forKey:@"item_images"];
[dict1 release];
[dict2 release];
[request setPostValue:[dict JSONRepresentation] forKey:@"item_post"];
[request setPostFormat:ASIMultipartFormDataPostFormat];
[request setTimeOutSeconds:200];
[request setDelegate:self];
[request setDidFinishSelector:@selector(uploadRequestFinished:)];
[request setDidFailSelector:@selector(uploadRequestFailed:)];
[request startSynchronous];
[requestUrlString release];