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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:42:50+00:00 2026-06-06T08:42:50+00:00

I am trying to set up a NSURLRequest to download a simple index.html with

  • 0

I am trying to set up a NSURLRequest to download a simple index.html with its externa style.css sheet but I am not quite sure how to do this.. I have only ever just formatted the URL of the request to the file I want.. but this has to be slightly different and I cannot find a good example of what I am trying to do.

this is my code so far:

#pragma mark - NSURLConnection methods

- (void)htmlRequest
{
    // Create the request.
    NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.mywebsite.com/index.html"]
                                              cachePolicy:NSURLRequestReloadIgnoringCacheData
                                          timeoutInterval:60.0];

    // create the connection with the request
    // and start loading the data
    NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    if (theConnection) {
        // Create the NSMutableData to hold the received data.
        // receivedData is an instance variable declared elsewhere.
        receivedData = [NSMutableData data];
    } else {
        // Inform the user that the connection failed.
        NSLog(@"Connection Fail");
    }
}


- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    // This method is called when the server has determined that it
    // has enough information to create the NSURLResponse.

    // It can be called multiple times, for example in the case of a
    // redirect, so each time we reset the data.

    // receivedData is an instance variable declared elsewhere.
    [receivedData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{

    // Append the new data to receivedData.
    // receivedData is an instance variable declared elsewhere.
    [receivedData appendData:data];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    // inform the developer of error type

}

// This method uses methodName to determin which Initalizer method to send the response data to in EngineResponses.m
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
//    EngineResponses *engineResponses = [EngineResponses sharedManager];

//        [engineResponses GetManufacturers:receivedData];

    NSString *myString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];
    NSLog(@"%@", myString);

}

as you can see I am just calling index.html directly.. I would like to know how to format my request so i get the index.html as well as style.css

any help would be greatly appreciated.

  • 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-06-06T08:42:52+00:00Added an answer on June 6, 2026 at 8:42 am

    I always create a new data structure,which has a -connection property and a -request property,like this

    @interface connectionWrapper : NSObject
    @property(retain) NSURLRequest *request
    @property(retain) NSURLConnection *connection
    

    by retaining this data structure in an mutable array, you can distinguish the connections in callback methods by iterate the array and compare each connectionWrapper instance’s -connection property with the connection parameter the of the callback method, if they match(points to a same object), then you can retrieve the -request property of the connectionWrapper instance, then -url property of NSURLRequest instance.

    as I’m not an native English speaker, I think code is a better tutor.

    -(NSURLRequest*)getRequestByConnection:(NSURLConnection*)connection
    {
        for(connectionWrapper *w in theArrayContainingAllConnectionWrappers)
        {
            if(w == connection)
                return w.request;
        }
    }
    

    In callback method:

    -(void)connection:(NSURLConnection*)connection didReceiveResponse(NSURLResponse*)response
    {
        NSURLRequest *request = [self getRequestByConnection:connection];
        NSURL *url = [request url];
        /*apply different approach to different url/*
    }
    

    PS:it’s very sad that NSURLConnection don’t have a -request property so that we can retrieve the request associated with the connection easily.

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

Sidebar

Related Questions

I am trying set up a simple dropdown list but I dont seem to
I trying to set rounded border for Blackberry Bitmap field.But it is not working
Trying to set a flag in the post to allow processing or not. The
When trying to set DoMatchParen I get the following error: E492: Not an editor
It is quite a simple question from me today. Is it possible to set
Im trying to set my tabs as a scrollbar. I have 6 tabs but
I'm trying set an text AND X (Close) label in header of rich:panel, but
Trying to set up a project but fail at Autowiring objects through Spring. package
Trying to set this textbox <%= Html.TextBoxFor(m => m.IndicationCalculatorNewGroupName, new {propertyName = IndicationCalculatorNewGroupName, onchange
Trying to set up a simple login script in flex 4 with php. In

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.