Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7687131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:38:03+00:00 2026-05-31T19:38:03+00:00

I use sendSynchronousRequest:returningResponse:error method of NSURLConnection class to get NSData from network. http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html NSData

  • 0

I use sendSynchronousRequest:returningResponse:error method of NSURLConnection class to get NSData from network.

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html

NSData *urlData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

What I want to do is to check if returned value is valid or not.
So, what I did was to compare the length of the data with expected length in response header as below.

NSData *urlData;
do {
    urlData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    if ([urlData length] != [response expectedContentLength]) {
        NSLog(@"WTF!!!!!!!!! NSURLConnection response[%@] length[%lld] [%d]", [[response URL] absoluteString], [response expectedContentLength], [urlData length]);
        NSHTTPURLResponse *httpresponse = (NSHTTPURLResponse *) response;
        NSDictionary *dic = [httpresponse allHeaderFields];
        NSLog(@"[%@]", [dic description]);
    }
} while ([urlData length] != [response expectedContentLength]);

However, I don’t know if it is enough to ensure the integrity of returned data.
I can’t check checksum of the file on the remote server.

Can you share your experience or other tips?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:38:04+00:00Added an answer on May 31, 2026 at 7:38 pm

    Create two variables in the class to store the length of data currently downloaded and the length of data expected (you could do more elegant)

    int downloadedLength;
    int expectedLength;
    

    To know the lenght of expected data you have to get it from didReceiveResponse delegate

    -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
    
    //    NSLog(@"expected: %lld",response.expectedContentLength);
        expectedLength = response.expectedContentLength;
        downloadedLength = 0;
    }
    

    to update the downloadedLenght, you have to increase it in didReceiveData:

    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    downloadedLength = downloadedLength + [data length];
    //...some code
    }
    

    then it is possible to do any logic to compare if downloaded data fit your requirements in connectionDidFinishLoading

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

    I had to do this to fix HJCache library issues with big pictures that downloaded incomplete (in HJMOHandler).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get an NSData object's contents from a URL. What is the
use LWP::Simple; use Parallel::ForkManager; @links=( [http://prdownloads.sourceforge.net/sweethome3d/SweetHome3D-2.1-windows.exe,SweetHome3D-2.1-windows.exe], [http://prdownloads.sourceforge.net/sweethome3d/SweetHome3D-2.1-macosx.dmg,SweetHome3D-2.1-macosx.dmg], [http://prdownloads.sourceforge.net/sweethome3d/SweetHome3DViewer-2.1.zip,SweetHome3DViewer-2.1.zip], ); # Max 30 processes for
I am trying to use a web service built on asp.net wcf from iPhone
NSString *urlAddress = @http://www.test.com/test.jsp?Query=哈囉; NSURL *url = [NSURL URLWithString:urlAddress]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
I would like to get some information from a website. I have already got
I wanted a quick and easy way to get data from a URL without
I want to make http form post using NSURLConnection in iOS. I have two
within the applicationDidEnterBackground method my program receives the bad signal EXC_BAD_ACCESS error. on the
My friend saw my code, a part is get a plist data from URL
Here I got from JSON [{photo:null}] and I use this code NSMutableArray *jPhoto =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.