0

I am making iPad application, in which, I am fetching data from a URL. Sometimes, I retrieved Null instead.

In my URL i am passing my id dynamically, for eg: in this code i passed id = PNB, here is the code snippet:

     NSMutableString*str;

     NSString *urlAddress = @”http://ipad.idealake.com/stockquote.aspx?id=PNB”;
     NSURL *url = [NSURL URLWithString:urlAddress];
     NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
     [webView loadRequest:requestObj];

str=[NSMutableString alloc] initWithContentsOfURL:url]; //(here compiler shows me warning initWithContentsOfURL is deprected)

          NSLog(@"str=%@",str);

When I do NSLog of str, it shows me null value,

output: str=null

However, when I pass id=SUNPHARMA or id=AMBUJA it shows me proper output but when i pass id=TCS or id=LT it again shows me null value in my str. What went wrong?

3 Answers 3

1

you have to trim your id , and try...

Sign up to request clarification or add additional context in comments.

Comments

0

The reason for getting nil is probably because the id argument is sometimes wrong (TCS or LT). Double check them, the URL probably hasn't any information to give in response.

About the warning, as stated in the doc, the initWithContentsOfURL: method is deprecated since iOS 2.0, you are encouraged to use initWithContentsOfURL:encoding:error: instead.

2 Comments

dude you rock.. can you write syntex for the same ?
this should look like : str=[[NSMutableString alloc] initWithContentsOfURL:url encoding:NSUTF8StringEncoding error:NULL]; assuming you use utf-8
0

PLease use ASIHTTPRequest LIB to solve all your problem. They do download data to memory or directly to a file on disk, cache responses and download progress indicators for operation queues. http://allseeing-i.com/ASIHTTPRequest/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.