Reputation: 399
i am tired to do this..but i can't get respose..
NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"access_name", @"about us", nil];
NSDictionary *finalDict = [[NSDictionary alloc] initWithObjectsAndKeys:dict, @"cmscontent", nil];
NSString * post =[NSString stringWithFormat:@"%@",finalDict];
NSData *postdata= [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength=[NSString stringWithFormat:@"%lu",(unsigned long)[postdata length]];
NSMutableURLRequest *request= [[NSMutableURLRequest alloc]init];
NSString *str=@"http://my url...";
[request setURL:[NSURL URLWithString:str]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postdata];
NSError *error;
NSURLResponse *response;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *returnstring=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSMutableDictionary *dict12=[returnstring JSONValue];
NSLog(@"%@",dict12);
and my json dictionary parameter is..
{
"cmscontent":
{
"access_name": "about us"
}
}
so please tell me how can i get response?? thanks in advance.
Upvotes: 0
Views: 1039
Reputation: 38
Change the forHTTPHeaderField content type vale
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
i hope this will resolve.. Thanks
Upvotes: 1