MH16
MH16

Reputation: 2356

How to send the updated data using json to server in iphone?

am using web services (JSON). from json am getting data this data loading into tableview am trying to edit this data but after edit the data how to send this updated data to server. please any one help me?

Upvotes: 1

Views: 714

Answers (2)

Kartik
Kartik

Reputation: 779

try this will help you.. this is the post method for updating data in WS .

NSString *post =[NSString stringWithFormat:@"uid=%@&firstname=%@&lastname=%@&phone=%@&bday=%@&about_me=%@&image=%@&image_code=%@&contact_number=%@",LoginID,fname,lname,cn,bday,abtme,strimage11,c11,cn];


NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];


NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"YOUR LINK"]];

[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"application/x-www-form-urlencoded charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];

NSError *error;
NSURLResponse *response;
NSData *uData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *data=[[NSString alloc]initWithData:uData encoding:NSUTF8StringEncoding];
//    
NSMutableDictionary *temp = [data JSONValue];
//    
NSLog(@"%@",temp);

Upvotes: 1

Srikar Appalaraju
Srikar Appalaraju

Reputation: 73588

I am assuming you have your edited data, then

  1. Form your json. There are several libraries out there which can help you.
  2. Know the hostname of your server.
  3. Know which API to hit on your server.
  4. then pass this json as POST (GET is also ok, but POST is preferred).
  5. Process this received json on your server.

Hope this helps. Nothing much to it actually.

Upvotes: 0

Related Questions