Unable to read xml file

There was a small problem getting the contents of the xml file (using TouchXML).

My first request works very well, looks something like this:

NSString *url = [NSString stringWithFormat:STATION_ID, latitude, longtitude];
CXMLDocument *rssParser = [[CXMLDocument alloc] initWithContentsOfURL:[NSURL URLWithString:url] options:0 error:nil];
NSLog(@"%@",rssParser);

so this log gives me the full xml file.

after that, in another method, I try to do the same:

NSString *url = [NSString stringWithFormat:WEATHER_URL, [positionInformation objectForKey:@"stationId"]];
CXMLDocument *rssParser = [[CXMLDocument alloc] initWithContentsOfURL:[NSURL URLWithString:url] options:0 error:nil];
NSLog(@"%@", rssParser);

but getting log im (null). The Loggin URL String gives me the correct URL without spaces or anything else, for example, the URL looks like this:

NSString *url = [NSString stringWithFormat:WEATHER_URL, [positionInformation objectForKey:@"stationId"]];
NSLog(@"%@", url);

Result in the debugger console

http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=KCASUNNY19

viewing this file with my browser seems to be in order. Does anyone know what is going wrong ?????

I also tried first getting the contents of this url using stringWithContentsOfURL, but that didn't work either.

+3
4

: http://www.iphonedevsdk.com/forum/iphone-sdk-development/15963-problem-initwithcontentsofurl.html. , API Weather Underground 500 HTTP-, . -initWithData:options:error: CXMLDocument , , NSMutableURLRequest.

+2

initWithContentsOfURL: options: error:. NSerror * :

NSError      *error;
CXMLDocument *rssParser = [[CXMLDocument alloc] initWithContentsOfURL:[NSURL URLWithString:url] options:0 error: &error];

rssParser, .

0

xml URL-. , , .asp.

. XML-, .

//: php , asp:

<?php
  echo file_get_contents("http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=KCASANFR70");
 ?>

script , , .

oh damn =/

0
source

Are you sure your URL string is correctly encoded so that the question mark is interpreted as a request? You might want to look at usage dataUsingEncodingor stringUsingEncodingat your URL before using it for initialization rssReader.

0
source

Source: https://habr.com/ru/post/1729687/


All Articles