views:

329

answers:

1

Hi,

I'm trying to get the following code to run (it's from the Heads First iPhone Development book - page 81), it's a twitter app, and the code blow runs when you press a button to send a simple text message to twitter:

//TWITTER BLACK MAGIC
    NSMutableURLRequest *theRequest=[NSMutableURLRequest
requestWithURL:[NSURL URLWithString:@"http://username:[email protected]/statuses/update.xml"]
cachePolicy:NSURLRequestUseProtocolCachePolicy 

    timeoutInterval: 60.0];
    [theRequest setHTTPMethod:@"POST"];
    [theRequest setHTTPBody:[[NSString stringWithFormat:@"status=%", themessage] dataUsingEncoding:NSASCIIStringEncoding]];

    NSURLResponse* response;
    NSError* error;
    NSData* result = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];
    NSLog(@"%@", [[[NSString alloc] initWithData:result encoding:NSASCIIStringEncoding] autorelease]);
    //END TWITTER BLACK MAGIC

and it does to a certain extent i.e the code runs but you can't see the result on Twitter - the resopnse I get back from Twitter in the debug window is:

  <request>/statuses/update.xml</request>
  <error>Client must provide a 'status' parameter with a value.</error>

Any ideas?

+2  A: 

It looks like you should use '%@' instead of '%' in your format string:

[theRequest setHTTPBody:[[NSString stringWithFormat:@"status=%@", themessage] dataUsingEncoding:NSASCIIStringEncoding]];
gerry3
Hmmm, it's really easy to misread Obj-C, when you're just starting out. Thanks, it all works lovely now!
Vidar