我在编写与具有SOAP WS接口的应用程序通信的IPhone / IOS Obj-C SOAP客户端时遇到问题。该应用程序使用NuSOAP php webserver并使用gzip / deflate对任何超过一定大小的有效负载进行编码,无论客户端启用哪一个。
我理解NSURLConnection透明地解压缩任何gzip编码的响应并呈现解压缩的响应,但在这种情况下收到的原始响应似乎已损坏。我将SOAP有效负载转储到一个文件中,并使用gunzip解压缩它,它抱怨“意外的文件结束”。我确实检查了网络服务器并将其发送到文件的gzip响应转储,使用gunzip解压缩时没有任何错误。似乎响应在收到时已经损坏。
我尝试使用NSURLConnection和ASIHTTPRequest。使用NSURLConnection,响应数据长度和响应的HTTP头中提到的长度之间每次恰好有15个字节的差异。使用ASIHTTPRequest接收的字节数和HTTP头中的响应长度匹配,但是响应仍然是损坏的,并且不会对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”=“no-store,no-cache,must-revalidate, post-check = 0,pre-check = 0“; 连接=“保持活力”; “Content-Encoding”= gzip; “内容长度”= 1683; “Content-Type”=“text / xml; charset = UTF-8”; Date =“Mon,04 Oct 2010 08:07:14 GMT”; Expires =“Thu,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; 路径= /“; 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]回复:
答案 0 :(得分:3)
可能是这个链接可以帮助你...... code generation for soap
答案 1 :(得分:0)
我曾经有一个问题,当一个稍微损坏的文件在我的Mac上没有任何问题解压缩,但在iPhone上它不会。我猜iPhone上的zlib对错误的容忍度较低。
答案 2 :(得分:0)
您确定-connection:didReceiveData:
之前至少没有调用-connection:didReceiveResponse:
一次吗?看起来您可能会截断带有标头的第一个数据包中的一些数据。
答案 3 :(得分:0)
您确定您的数据是UTF8吗?尝试其他编码,看看你的错误是否消失。