Parsing XML from a Https URL using NSXMLParser?

  • I'm trying to parse XML directly from an HTTPS URL, as follows:

    NSString *const URL = @"https://some/HTTPS/url";
    NSURL* url = [NSURL URLWithString:URL];NSXMLParser* parser = [[NSXMLParser
    alloc] initWithContentsOfURL:url];
    [parser setDelegate:self];
    [parser parse];

    I have the following delegate method for the parser:

    - (void) parser:(NSXMLParser *)parser
    didStartElement:(NSString *)elementName
    namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString
    *)qualifiedName
    attributes:(NSDictionary *)attributeDict
    {
        NSLog(@"Started parsing %@", elementName);
    }

    This seems to work fine for HTTP URL's, but shows no result for an HTTPS
    URL.

    How could I fix this?
  • On 7 Jan 2009, at 11:24, Debajit Adhikary wrote:

    > I'm trying to parse XML directly from an HTTPS URL, as follows:
    >
    > NSString *const URL = @"https://some/HTTPS/url";
    > NSURL* url = [NSURL URLWithString:URL];NSXMLParser* parser =
    > [[NSXMLParser
    > alloc] initWithContentsOfURL:url];
    > [parser setDelegate:self];
    > [parser parse];

    [snip]

    > This seems to work fine for HTTP URL's, but shows no result for an
    > HTTPS
    > URL.
    >
    > How could I fix this?

    I don't think the problem is the HTTPS url scheme as such.  It's more
    likely something to do with the server at the far end.  For instance,
    your HTTPS URL may require that some credentials are passed to the
    server (e.g. if it's using HTTP Basic auth.), and in that case I don't
    see how the -initWithContentsOfURL: method would know what to do on
    its own.

    In that case, you might need to use NSURLConnection/NSURLRequest to do
    the fetch from the server first, so that you can respond to the
    relevant delegate methods and provide the necessary authentication data.

    Kind regards,

    Alastair.

    --
    http://alastairs-place.net