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 so开发者_高级运维me 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.
精彩评论