2011-12-02 79 views

回答

0

我假设你有你编辑的数据,然后

  1. 形成你的JSON。有几个图书馆可以帮助你。
  2. 知道您的服务器的主机名。
  3. 知道在您的服务器上打哪个API。
  4. 然后通过这个json作为POST(GET也可以,但POST是首选)。
  5. 在您的服务器上处理收到的json。

希望这会有所帮助。实际上没什么大不了的。

1

试试这个会帮助你..这是在WS中更新数据的post方法。

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); 
相关问题