- (NSDictionary*)PostWebService:(NSString*)completeURL param:(NSString*)value
{
@try
{
NSString *urlStr =[completeURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:urlStr];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
//NSString *urlPart=@"req=value";
//NSString *urlPart;
NSString *urlPart=[NSString stringWithFormat:@"req=%@", value];
NSLog(@"String %@",urlPart);
NSData *requestBody = [urlPart dataUsingEncoding:NSUTF8StringEncoding];
//NSLog(@"String %@",requestBody);
[request setHTTPBody:requestBody];
NSURLResponse *response = NULL;
NSError *requestError = NULL;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&requestError];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding] ;
NSLog(@"String %@",responseString);
NSError* error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData
options:kNilOptions
error:&error];
return json;
}
@catch(NSException *e)
{
NSLog(@"reason is%@",e.reason);
}
}
and i call this method here..
-(NSDictionary*)gotvall:(NSString*)req
{
@try
{
NSString *vurl=@"some url/";
// vurl=[vurl stringByAppendingString:@"req="];
// vurl=[vurl stringByAppendingString:req];
// NSLog(@"%@",vurl);
NSDictionary *json=[self PostWebService:vurl param:req];
NSLog(@"json is%@",json);
return json;
}
@catch(NSException *e)
{
NSLog(@"%@",e.reason);
}
}
After debugging this method I got result as data parameter is nil
.
Can anyone tell that what I am doing wrong here.
I got the complete url and when I run that url on browser I got the perfect data but when I printing the value of json it returns null
.