【发布时间】:2011-04-20 17:58:17
【问题描述】:
我在编写与具有 SOAP WS 接口的应用程序通信的 iPhone/IOS Obj-C SOAP 客户端时遇到问题。该应用程序使用 NuSOAP php 网络服务器并使用 gzip/deflate 对任何超过特定大小的有效负载进行编码,以客户端启用的为准。
我了解 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] 标头:{ "Cache-Control" = "无存储,无缓存,必须重新验证, 后检查=0,预检查=0”; 连接=“保持活动”; “内容编码”= gzip; “内容长度”= 1683; “内容类型”=“文本/xml;字符集=UTF-8”; 日期 = “星期一,2010 年 10 月 4 日 08:07:14 GMT”; Expires = "1981 年 11 月 19 日星期四 08:52:00 GMT"; “保活”=“超时=15,最大值=100”; Pragma = "无缓存"; 服务器 = "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 = "接受编码"; "X-Powered-By" = "PHP/5.2.5"; "X-Soap-Server" = "NuSOAP/0.7.2 ()"; } 2010-10-04 13:37:15.311 糖皂[848:207]
didReceiveData :(null) 2010-10-04 13:37:15.311 SugarSoap[848:207] 连接完成!长度: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] 响应:
【问题讨论】:
标签: iphone objective-c cocoa xcode soap