Using Swift to handle a GZipped HTTP response (containing JSON)

I wrote Android apps that take GZipped Json data from an HTTP response. Now I want to write some IPhone applications that do the same.

What class and approaches are needed to process GZipped Json data using Swift?

+4
source share
1 answer

From the quick side:

  • gzip. Alamofire. NSURLConnection/NSURLSession, gzipped. ( , ). , php- gzipped, ( alamofire) . ... : "Content-encoding: gzip".
  • gzip. iOS PHP (, php) .

php:

  • gzip. (gzipped) post ( iOS) :

    // Read the post data
    $handle = fopen("php://input", "rb");
    $raw_post_data = '';
    while (!feof($handle)) {
       $raw_post_data .= fread($handle, 8192);
    }
    fclose($handle);
    
    // unzip the post data
    $raw_post_data_unzipped = gzdecode($raw_post_data);
    
  • gzip. gzipped- ( iOS), - php .

    ob_start('ob_gzhandler');
    
+3

All Articles