@interface urlPostMethod: NSObject
{
}
-(void) reDirect;
@end
@implementation urlPostMethod
-(void) reDirect{
NSString *post = [NSString stringWithFormat:@"text1=MYNAME"];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
//NSString *postLength = [NSString stringWithFormat:@"",[postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://10.0.0.7:8080/UrlProject/DemoUrl.jsp"]]];
[request setHTTPMethod:@"POST"];
//[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];
[request setHTTPBody:postData];
NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self];
if(conn)
{
NSLog(@"Connection Successful");
}
else
{
NSLog(@"Connection could not be made");
}
}
@end
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
urlPostMethod* urlPost= [[urlPostMethod alloc]init];
[urlPost reDirect];
[pool drain];
return 0;
}