WEB开发网
开发学院手机开发iPhone 开发 iphone 实行http post 及多线程编程 阅读

iphone 实行http post 及多线程编程

 2010-07-06 05:10:00 来源:WEB开发网   
核心提示:#import "FirstUIAppDelegate.h"@implementation FirstUIAppDelegate@synthesize window;- (void)applicationDidFinishLaunching:(UIApplication *)application

#import "FirstUIAppDelegate.h"

@implementation FirstUIAppDelegate

@synthesize window;

- (void)applicationDidFinishLaunching:(UIApplication *)application {

// Override point for customization after application launch

//[self postdata];

[self setupThread];

[window makeKeyAndVisible];

}

-(void)setupThread{

[NSThread detachNewThreadSelector:@selector(postdata)toTarget:self withObject:nil];

}

- (void)dealloc {

[window release];

[super dealloc];

}

-(void)postdata{

NSLog(@"TEST");

NSURL *url;

NSMutableURLRequest *urlRequest;

NSMutableData *postBody = [NSMutableData data];

url = [NSURL URLWithString:@"http://allove.org"];

urlRequest = [[[NSMutableURLRequest alloc] initWithURL:url] autorelease];

[urlRequest setHTTPMethod:@"POST"];

NSString *udid = @"phong=15871485145&psw=23";

[postBody appendData:[udid dataUsingEncoding: NSUTF8StringEncoding allowLossyConversion:YES]];

[urlRequest setHTTPBody:postBody];

NSData *returnData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:nil error:nil];

if(returnData)

{

NSString *result = [[NSString alloc] initWithData:returnData encoding:NSASCIIStringEncoding];

NSLog(@"result=======>%@",result);

}

else

{

NSLog(@"Wrong Connetion!");

}

}

@end

Tags:iphone 实行 http

编辑录入:coldstar [复制链接] [打 印]
赞助商链接