title: How to fetch a webpage in a quicklook plugin?
body: <p>My plugin has to make a google request and then display another page's HTML content.<br>
  I have only been able to display HTML so far, even though QuickLook is supposed to support network access!</p>
  
  <p><strong>kng</strong> <a href="https://github.com/kgn/QLWebloc" rel="nofollow">attempted to fetch pages</a> (building a .webloc viewer), with no luck, then said in the README</p>
  
  <blockquote>
    <p>Quicklook in Lion now does what this project attempted to do.</p>
  </blockquote>
  
  <p>I have Mountain Lion and have applied similar patterns, as shown below, with still no luck. Nobody on the web seem to have ever tried to access an URL from a QuickLook plugin; besides the undocumented WebLoc plugin provided by Apple. Moreover, the QuickLook Programing Guide is <em>4 years old</em>.</p>
  
  <p>What I have tried:</p>
  
  <pre><code>OSStatus GeneratePreviewForURL(void *thisInterface,
                                 QLPreviewRequestRef preview,
                                 CFURLRef url,
                                 CFStringRef contentTypeUTI,
                                 CFDictionaryRef options)
  {
      if (QLPreviewRequestIsCancelled(preview))
          return noErr;
  
      //// Fetch Web Page
  
      NSData *data;
      NSError *err;
  
      /// Attempt 0: static HTML -- ok
      //NSString *html = @"&lt;html&gt;&lt;body&gt;&lt;h1&gt;It works!&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;";
  
      /// Attempt 1: dataWithContentsOfURL -- ko
      data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://google.com/"] options:NSDataReadingUncached error:&amp;err];
  
      /// Attempt 2: NSURLConnection -- ko
      //NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com/"]];
      //NSURLResponse *response;
      //data = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&amp;response error:&amp;err];
  
  
      // Builds /Users/pete/out.txt on error
      NSString *html = [[NSString alloc] initWithData:(NSData *)data encoding:NSUTF8StringEncoding];
      [err.description writeToFile:@"/Users/pete/out.txt" atomically:YES encoding:NSUTF8StringEncoding error:nil];
  
      //// Display HTML
  
      NSMutableDictionary *props;
      [props setObject:@"UTF-8" forKey:(NSString *)kQLPreviewPropertyTextEncodingNameKey];
      [props setObject:@"text/html" forKey:(NSString *)kQLPreviewPropertyMIMETypeKey];
  
      QLPreviewRequestSetDataRepresentation(preview,
                                            (__bridge CFDataRef)[html dataUsingEncoding:NSUTF8StringEncoding],
                                            kUTTypeHTML,
                                            (__bridge CFDictionaryRef)props);
      return noErr;
  }
  </code></pre>
  
  <p>The complete code &amp; environment <a href="https://bitbucket.org/fenollp/qlimdb/src" rel="nofollow">can be found here</a></p>