Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Ho to use: await client.GetAsync("url"); method in App.cs?

$
0
0

I need to get a webservice response with HttpClient in App.cs class(i.e. when app starts). I am able to get the response in other pages but in App class it is throwing error : Object Reference is set to null.
See my sample code:

            var client = new HttpClient();         
            client.BaseAddress = new Uri(geturl);
            client.DefaultRequestHeaders.Add("headone", username);
            client.DefaultRequestHeaders.Add("headtwo", pass);

            var response = await client.GetAsync(url);
            var ResultHTML = reponse.Content.ReadAsStreamAsync().Result;

Debugger shows Error in this line : var response = await client.GetAsync(url);
This code is working file for all other pages but why it is showing error in App class.
I have tried all the possible solutions given in this link: https://forums.xamarin.com/discussion/10405/the-authentication-or-decryption-has-failed-in-the-web-request

But nothing worked for me. Please help me in resolving this error. I have to fetch response from the Httpclient if user is already logged-in otherwise go to the login page. So I have to write GetAsync() code in App class.
Please reply.
Error: System.NullReferenceException: Object reference not set to an instance of an object.


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>