我在写一个IPhone/IOS Obj-C SOAP客户端时遇到了麻烦,该客户端使用SOAP WS接口与应用程序对话。该应用程序使用NuSOAP PHP网络服务器,并使用gzip/deflate编码超过一定大小的任何有效载荷,无论客户端是否启用。NSURLConnection:gzip编码的SOAP响应被破坏
据我所知,NSURLConnection透明地解压缩任何gzip编码响应,并呈现解压缩的响应,但在这种情况下收到的原始响应似乎已损坏。我将SOAP有效载荷转储到一个文件中,并使用gunzip将其解压缩,它抱怨“文件意外结束”。我确实检查了网络服务器,并将其发送到文件的gzip响应转储,这是使用gunzip解压缩的,没有任何错误。似乎收到的响应已经损坏。
我试过使用NSURLConnection和ASIHTTPRequest。使用NSURLConnection时,响应数据长度和响应的HTTP头中提到的长度之间每次只有15个字节的差异。使用ASIHTTPRequest接收到的字节数和HTTP Header中响应的长度匹配,但是可惜的是响应仍然是错误的,并且对gzip解压缩没有反应。
- (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]接头:{ “缓存控制”=“不存储,无缓存,必重新验证, 后检查= 0,预检= 0“; Connection =“Keep-Alive”; “内容编码”= gzip; “Content-Length”= 1683; “Content-Type”=“text/xml; charset = UTF-8”; Date =“Mon,04 Oct 2010 08:07:14 GMT”; Expires =“星期四,1981年11月19日08:52:00 GMT”; “Keep-Alive”=“timeout = 15,max = 100”; Pragma =“no-cache”; Server =“Apache/2.0.59(Unix)mod_ssl/2.0.59 OpenSSL/0.9.8g DAV/2 PHP/5.2.5”; “Set-Cookie”=“PHPSESSID = udsgtttvts90ijuhsvuqop6ja6; path = /”; 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:(空)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]回应:
是的,它被调用以正确的顺序。我记录了所有收到的数据,猜测数据即使被调用失序也应该显示出来。另请注意,如果我在WS服务器端禁用gzip编码,则SOAP调用完美地工作。 – Bala 2010-11-09 06:26:30