我从XML格式的.net Web服务获得了压缩响应字符串。如何解码响应字符串?
我的代码如下所示。
NSString *mysUrl=@"myurl";
NSString *soapMsg1 = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
"<soap:Body>\n"
"<CompressString xmlns=\"http://tempuri.org/\">"
"<text>%@</text>"
"</CompressString>"
"</soap:Body>\n"
"</soap:Envelope>",@"abcdefghijklmonpqrstuvwxyz"];
NSLog(@"%@",soapMsg1);
NSURL *url1 = [NSURL URLWithString:mysUrl];
NSMutableURLRequest *req1 = [NSMutableURLRequest requestWithURL:url1];
NSString *msgLength1 = [NSString stringWithFormat:@"%d", [soapMsg1 length]];
[req1 addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
NSLog(@"lenght of the message is.......%@",msgLength1);
[req1 addValue:@"http://tempuri.org/CompressString" forHTTPHeaderField:@"SOAPAction"];
[req1 addValue:msgLength1 forHTTPHeaderField:@"Content-Length"];
NSLog(@"lenght of the message is.......%@",req1);
[req1 setHTTPMethod:@"POST"];
[req1 setHTTPBody: [soapMsg1 dataUsingEncoding:NSUTF8StringEncoding]];
NSURLResponse *response;
NSError *error;
//getting the data
[req1 addValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];
NSData *newData = [NSURLConnection sendSynchronousRequest:req1 returningResponse:&response error:&error];
NSString *responseString = [[NSString alloc] initWithData:newData encoding:NSUTF8StringEncoding];
NSLog(@"\n\n\n Compression string response %@ \n\n\n",responseString);