Try the below code
Ref: http://stackoverflow.com/questions/5537297/ios-how-to-perform-an-http-post-request
+(NSData *)postDataToUrl:(NSString*)urlString:(NSString*)jsonString
{
NSData* responseData = nil;
NSURL *url=[NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
responseData = [NSMutableData data] ;
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
NSString *bodydata=[NSString stringWithFormat:@"data=%@",jsonString];
[request setHTTPMethod:@"POST"];
NSData *req=[NSData dataWithBytes:[bodydata UTF8String] length:[bodydata length]];
[request setHTTPBody:req];
NSURLResponse* response;
NSError* error = nil;
responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"the final output is:%@",responseString);
return responseData;
}
Ref: http://stackoverflow.com/questions/5537297/ios-how-to-perform-an-http-post-request
No comments:
Post a Comment