Bal*_*ala 5 iphone xcode cocoa soap objective-c
我在编写与具有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];
}
Run Code Online (Sandbox Code Playgroud)
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; path = /"; Vary ="Accept-Encoding"; "X-Powered-By"="PHP/5.2.
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);
}
Run Code Online (Sandbox Code Playgroud)
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]回复:
| 归档时间: |
|
| 查看次数: |
2530 次 |
| 最近记录: |