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

iphone 实行http post 及多线程编程实例

 2010-03-31 17:30: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 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
更多精彩
    赞助商链接

    热点阅读
      焦点图片
        最新推荐
          精彩阅读