Skip to content

Instantly share code, notes, and snippets.

@magicshui
Created May 5, 2012 07:18
Show Gist options
  • Save magicshui/2600587 to your computer and use it in GitHub Desktop.
Save magicshui/2600587 to your computer and use it in GitHub Desktop.
NSMutableURLRequest *request;
NSError *error;
NSURLResponse* response;
NSData *receivedData;
NSString*result;
static NSString* url_pic =@"http://douban.fm/misc/captcha?size=m&id=";
request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:url_fav_song]];
[request setValue:@"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" forHTTPHeaderField:@"Accept"];
[request setValue:@"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20100101 Firefox/11.0" forHTTPHeaderField:@"User-Agent"];
receivedData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if (receivedData) {
result=[[NSString alloc]initWithData:receivedData encoding:NSUTF8StringEncoding];
} else {
// Inform the user that the connection failed.
}
NSLog(@"receive data: %@",result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment