NSURLConnection: gzip encoded SOAP response corrupted

I am having trouble recording the IPhone / IOS Obj-C SOAP client that is talking to the SOAP WS-based application. The application uses the NuSOAP php web server and encodes any payload above a certain size with gzip / deflate, depending on what is enabled by the client.

I understand that NSURLConnection transparently decompresses any gzip-encoded response and is a decompressed response, but the original answer received in this case seems to be corrupted. I dumped the SOAP payload into a file and unpacked it with gunzip, it complains about the "unexpected end of file". I checked the web server and dumped the gzip response that it sends to the file, it is unpacked without any error using gunzip. It seems that the response gets damaged upon receipt.

I tried using NSURLConnection and ASIHTTPRequest. With NSURLConnection, the difference is exactly 15 bytes each time between the length of the response data and the length specified in the HTTP response header. With ASIHTTPRequest, the number of bytes received and the length of the response in the header of the HTTP header, but, alas, the response is still corrupted and does not respond to gzip decompression.

    - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    NSLog(@"Headers :%@",[(NSHTTPURLResponse*)response allHeaderFields]);
        [self.receivedData setLength:0];
    self.receivedData = [[NSMutableData dataWithCapacity:1024*1024] retain];
   }

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)value {
    NSString *dataRec = [[NSString alloc] initWithData:value encoding:NSUTF8StringEncoding];
    NSLog(@"didReceiveData :%@",dataRec);
    [self.receivedData appendData:value];
}

2010-10-04 13: 37: 15.310 SugarSoap [848: 207] : {      "Cache-Control" = "no-store, no-cache, must-revalidate, post-check = 0, pre-check = 0";     Connection = "Keep-Alive";      "Content-Encoding" = gzip;      "Content-Length" = 1683;      "Content-Type" = "text/xml; charset = UTF-8";     Date = "Mon, 04 Oct 2010 08:07:14 GMT";     Expires = "Thu, 19 1981 08:52:00 GMT";      "Keep-Alive" = "timeout = 15, max = 100";     Pragma = "no-cache";      = "Apache/2.0.59 (Unix) mod_ssl/2.0.59 OpenSSL/0.9.8g DAV/2 PHP/5.2.5";      "Set-Cookie" = "PHPSESSID = udsgtttvts90ijuhsvuqop6ja6; =/";     Vary = "Accept-Encoding";      "X-Powered-By" = "PHP/5.2.5";      "X-Soap-Server" = "NuSOAP/0.7.2()"; } 2010-10-04 13: 37: 15.311 SugarSoap [848: 207]

didReceiveData: (null) 2010-10-04 13: 37: 15.311 SugarSoap [848: 207] connectionFinsihed! : 1668

-(void)requestFinished:(ASIHTTPRequest *)request {
    if([request isResponseCompressed]){
        NSLog(@"Response Compressed.");
    }
    NSData *compressedResponse = [request rawResponseData];
    NSData *responseData = [request responseData];
    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding];
    NSLog(@"Length before decompression:%d Length after decompression:%d", compressedResponse length],[responseData length]);
    NSLog(@"Response :%@",responseString);
}

2010-10-04 14: 11: 20.687 Hello_SOAP [1033: 207] .

2010-10-04 14: 11: 20.687 Hello_SOAP [1033: 207] : 2165 : 0

2010-10-04 14: 11: 20.687 Hello_SOAP [1033: 207] :

+5
4

, ...

+3

- , - Mac, iPhone . , zlib iPhone .

0

, -connection:didReceiveData: -connection:didReceiveResponse:? , , .

0

Are you sure your data is UTF8? Try other encodings and see if the error disappears.

0
source

All Articles