Reputation: 553
http://novatoresols.com/demos/blow/users/add.json?json={"email":"ali"}
How can I send a key
and data
to web? Here "email" is the key
and "ali" is the value in URL.
Code:
NSURL *url=[NSURL URLWithString:[hostURL stringByAppendingFormat:@"users/add.json?json="]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSString * params =@"{\"email\":\"Ali\"}";
[request setHTTPMethod:@"POST"];
// This is how we set header fields
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:[params dataUsingEncoding:NSUTF8StringEncoding]];
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
Upvotes: 0
Views: 1066
Reputation: 15335
Simply Try with this :
NSString * params =@"{\"email\":\"Ali\"}";
NSURL *url=[NSURL URLWithString:[hostURL stringByAppendingFormat:@"users/add.json?json=%@",params]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSLog (@"%@",data);
Upvotes: 1