简体   繁体   中英

Objective-C and TBXML: How to accept mime-type “application/xml” with TBXML?

The TBXML documentation is pretty small and the API didn't give me any hints as how I should define how to accept mime-type "application/xml" with TBXML, as I'm requesting data from a webservice that serves HTML as default but can serve XML if requested (and I need the XML).

Is there some way to do this with the API? Or is there a workaround? I didn't try any request processing with iOS SDK so far, so maybe there's an obvious answer I just don't see.

If you open TBXML source code, you'll see that initWithURL is defined as ...

- (id)initWithURL:(NSURL*)aURL {
    self = [self initWithXMLString:[NSString stringWithContentsOfURL:aURL encoding:NSUTF8StringEncoding error:nil]];

... and there's no way how to say that you want to receive XML.

You should look at NSMutableURLRequest, NSURLConnection and download it by yourself. You can set HTTP header field Accept in NSMutableURLRequest and then you can use this request in NSURLConnection to download it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM