技术与热点应用 您所在的位置:电子展览网 > 行业资讯 > 技术与热点应用 > 手机设计与制造

iphone 实行http post 及多线程编程




关键词:

  #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

分享到:
收藏 打印
相关新闻
  • 没有相关信息!