Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Legacy Documentclose button

Important: URL Access Manager is deprecated as of Mac OS X v10.4. You should use CFNetwork instead (as described in CFNetwork Programming Guide).

Setting and Determining URL Properties

To use URL Access Manager, you must first make sure that it is installed, and find out which version is installed. Your application can call the functions URLAccessAvailable and URLGetURLAccessVersion to determine this information.

In order to set and obtain URL properties, you must create a URL reference. To do this, call the function URLNewReference. URL Access Manager uses a URL reference to uniquely identify a URL and its associated data to be transferred. When you are finished with a URL, make sure you deallocate its memory by calling the function URLDisposeReference.

You can call the functions URLGetProperty and URLSetProperty to obtain and set information associated with a URL. You must pass the correct data type and size of the property value you wish to set in the propertyBuffer parameter of URLSetProperty. Before calling these functions, you should call the function URLGetPropertySize to determine the size of the buffer to allocate for the property value.

You may wish to call these functions before calling the functions URLDownload and URLUpload to get and set information associated with the specified URL in the urlRef parameter.

Once you have created a URL reference, you can create a function to display the properties of that reference. In “Listing 1-1,” the function displayProperties first creates a propertyList array of Apple-defined URL properties, obtains the corresponding sizes and values of these properties by calling URLGetPropertySize and URLGetProperty, respectively, and then displays each property value.

Listing 1-1  Displaying the value of each URL property

void displayProperties (URLReference urlRef)
{
    OSErr err = noErr;
    int propCount = 0;
    const char* propertyList[21];
    Size propertySize = 0;
    Handle theProperty = NULL;
    propertyList[0]  = kURLURL;
    propertyList[1] = kURLResourceSize;
    propertyList[2] = kURLLastModifiedTime;
    propertyList[3] = kURLMIMEType;
    propertyList[4] = kURLFileType;
    propertyList[5] = kURLFileCreator;
    propertyList[6] = kURLCharacterSet;
    propertyList[7] = kURLResourceName;
    propertyList[8] = kURLHost;
    propertyList[9] = kURLAuthType;
    propertyList[10] = kURLUserName;
    propertyList[11] = kURLPassword;
    propertyList[12] = kURLStatusString;
    propertyList[13] = kURLIsSecure;
    propertyList[14] = kURLCertificate;
    propertyList[15] = kURLTotalItems;
    propertyList[16] = kURLHTTPRequestMethod;
    propertyList[17] = kURLHTTPRequestHeader;
    propertyList[18] = kURLHTTPRequestBody;
    propertyList[19] = kURLHTTPRespHeader;
    propertyList[20] = kURLHTTPUserAgent;
 
    // Get the size of each property, allocate a handle to store the
    // property’s value, get the property value, and display it.
 
    for( propCount = 0; propCount < 21; propCount++)
    {
        // Get the size of the property’s value.
        err = URLGetPropertySize (urlRef, propertyList[propCount], &propertySize);
        if(err != noErr)
            printf("Error %d getting property size %s. Size returned was: %d\n", err, propertyList[propCount], propertySize);
        else
            printf("Property size is %d: %s\n", propertySize, propertyList[propCount]);
 
        // Now get a handle for the property value.
        theProperty = NewHandleClear (propertySize + 1);
        err = MemError();
        if(err != noErr)
            printf("Error %d getting property handle %s\n", err, propertyList[propCount]);
        else
            printf("Got handle for %s\n", propertyList[propCount]);
 
        // Now get the property’s value.
        err = URLGetProperty (urlRef, propertyList[propCount], *theProperty, propertySize);
        if(err != noErr)
            printf("Error %d getting property %s\n", err, propertyList[propCount]);
        else
            printf("Property %s: %s\n", propertyList[propCount], *theProperty);
 
        // Clean up.
        DisposeHandle (theProperty);
        printf("\n");
    }
    return;
}


< Previous PageNext Page > Hide TOC


Last updated: 2007-05-03




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice