如题。

解决方案 »

  1.   

    - (void) postToTwitter
    {
      // Since this will be launched in a separate thread, we need
      // an autorelease pool
      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     
      NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:
        [NSURL URLWithString:@"http://TWITTER_ACCOUNT:[email protected]/statuses/update.xml"] 
        cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
     
      // The text to post
      NSString *msg = @"testing";
     
      // Set the HTTP request method
      [request setHTTPMethod:@"POST"];
     
      [request setHTTPBody:[[NSString stringWithFormat:@"status=%@", msg] 
        dataUsingEncoding:NSASCIIStringEncoding]];
     
      NSURLResponse *response;
      NSError *error;
     
      if ([NSURLConnection sendSynchronousRequest:request 
          returningResponse:&response error:&error] != nil)
        NSLog(@"Posted to Twitter successfully.");
      else 
        NSLog(@"Error posting to Twitter."); 
     
      // Release pool
      [pool release]; 
    }