1

I need to communicate with server with SOAP request and get response. I have quite good method which creates XML request with parameters, transform it to NSMutableURLRequest and send with NSURLConnection. All of it works fine so I'll skip this part of code. My server is kind of Magento shop so I receive different amount of data depends what request I use. When I get short responses like session ID, everything works perfect, but when response is longer (list of countries for example) my data is lost somehow. I checked it by comparison of data length in didReceiveResponse and didReceiveData

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    self.expectedLength = response.expectedContentLength;
    self.downloadedLength = 0;
    [receivedData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    NSLog(@"Data recived");
    self.downloadedLength = self.downloadedLength + [data length];
    [receivedData appendData:data];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
        if (self.downloadedLength == self.expectedLength) {
            NSLog(@"correctly downloaded");
        }
        else{
            NSLog(@"sizes don't match");
        }

        str = [[NSString alloc] initWithBytes:[receivedData bytes] length:[receivedData length] encoding:NSISOLatin1StringEncoding];

        NSData *tmp_Data = [[NSData alloc] initWithData:[str dataUsingEncoding:NSISOLatin1StringEncoding allowLossyConversion:YES]];

        parser = [[SYXmlParser alloc]initWithData:tmp_Data];

        [parser startParser];

        if([parser theDataArray] != nil && [[parser theDataArray]count] != 0)
        {
            resultArray = [[NSMutableArray alloc]initWithArray:[parser theDataArray]];
            [self performSelectorOnMainThread:@selector(loadFinished) withObject:nil waitUntilDone:YES];
        }

    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

When response is long I got cut XML and my comparison returned "sizes don't match". XML is not cut definitely by half, but the data is missing in the middle of text, like some of characters is missing only. The issue repeats every time in same places in same way so its not random. I tried use AFNetworking to solve this problem, but I think I cant use it properly with this SOAP request. I will be grateful for every proposition which would fix this problem.

EDIT:

I used this Charles but there is the same problem as in xcode. When I open response tab and SOAP tab the response is null, on XML tab there is an error that Charles could't parse this received data, but in overview tab there is size of response 4666 bytes. Is that mean that server gives bad response? I cant believe it because its commercial server Magento which is used with many others languages and it works.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
  • Use Charles to check what is actually coming in and verify if the problem is app or server based. – Wain Oct 11 '13 at 19:59

0 Answers0