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 7075399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:10:22+00:00 2026-05-28T06:10:22+00:00

I am using if-modified-since in the HTTP header to decide if I should download

  • 0

I am using if-modified-since in the HTTP header to decide if I should download file.
App was tested and everything was OK, but now I am getting errors when I ask my NSHTTPURLResponse instance response.statusCode or [[response allHeaderFields] objectForKey:@"Last-Modified"].

It seems to be just NSURLResponse. What are the possible reasons?

I’ve readthis topic but the problem still is not clear for me.
Thanks in advance!
UPD:
some code:

        NSURL *url = [NSURL URLWithString:urlString];  
        NSFileManager *fileManager = [NSFileManager defaultManager];  

        NSMutableURLRequest *myRequest = [NSMutableURLRequest requestWithURL:url];  
        [myRequest setHTTPMethod:@"GET"];

        NSDateFormatter *df = [[NSDateFormatter alloc] init];  
        df.dateFormat = @"EEE',' dd MMM yyyy HH':'mm':'ss 'GMT'";  
        df.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];  
        df.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];  

        [myRequest addValue:[df stringFromDate:lastModifiedLocal]  forHTTPHeaderField:@"If-Modified-Since"];

        myRequest.cachePolicy = NSURLRequestReloadIgnoringLocalAndRemoteCacheData;

        NSHTTPURLResponse *response=nil;  
        NSError* error = nil;

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

        if (error) {
        NSLog(@"Error sending request: %@", [error localizedDescription]);
    }
//As was advised
        NSHTTPURLResponse* newResp = (NSHTTPURLResponse*)response;
//crash here        
NSLog(@"%d", newResp.statusCode);

UPD:
Error in code – myRequest and request are different variables. Problem solved.

  • 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-28T06:10:22+00:00Added an answer on May 28, 2026 at 6:10 am

    It is very likely that the request is failing and no response object is being generated. You can check this as follows:

    if (response) {
        NSHTTPURLResponse* newResp = (NSHTTPURLResponse*)response;
        NSLog(@"%d", newResp.statusCode);
    }
    else {
        NSLog(@"No response received");
    }
    

    As was suggested by another commenter, you should probably include an NSError object so you can check errors more effectively:

    NSHTTPURLResponse *response=nil;
    NSError *error = nil;  
    NSData* data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error: &error];  
    

    Then, you can check the error before checking the response:

    if (error) {
        NSLog(@"Error sending request: %@", [error localizedDescription]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do you get any file's last modified date using VB6?
How can I convince Firefox (3.0.1, if it matters) to send an If-Modified-Since header
Using PHP how can I accurately test that a remote website supports the If-Modified-Since
I was reading a tutorial http://www.raywenderlich.com/1914/how-to-save-your-app-data-with-nscoding-and-nsfilemanager about using NSCoding so that I can save
I'm using nested sets (aka modified preorder tree traversal) to store a list of
I'm using the DataLoadOptions to retrieve the User that modified a Customer's details, DataLoadOptions
I am using .Net Remoting and trying to access a remote object modified in
I'm using caml query to select all documents which were modified or added by
I created a site using wordpress. I installed the 'starkers' theme and modified it.
I am using DotNetOpenAuth in my ASP.Net Website. I have modified it to work

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.