0

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

Cybermaxs
  • 24,378
  • 8
  • 83
  • 112

2 Answers2

1

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.

Community
  • 1
  • 1
Lithu T.V
  • 19,955
  • 12
  • 56
  • 101
0
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];
GhostRider
  • 1,197
  • 10
  • 19