Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In normal i can call the my rest api, in xamarin andriod studio, i'm not able to call my api, its showing an NULL as my return status.

What I have tried:

C#
HttpClient client = new HttpClient();
            var uri = new Uri(string.Format("http://localhost:59803/api/Controller/ActionName?username=" + model.Email + "&Password=" + model.Password));
            HttpResponseMessage response; ;
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            response = await client.GetAsync(uri);
            if (response.StatusCode == System.Net.HttpStatusCode.Accepted)
            {
                var errorMessage1 = response.Content.ReadAsStringAsync().Result.Replace("\\", "").Trim(new char[1] { '"' });
                //Toast.MakeText(this, errorMessage1, ToastLength.Long).Show();
            }
            else
            {
                var errorMessage1 = response.Content.ReadAsStringAsync().Result.Replace("\\", "").Trim(new char[1] { '"' });
                //Toast.MakeText(this, errorMessage1, ToastLength.Long).Show();
            }
Posted
Updated 24-Jul-17 17:17pm
v2
Comments
Graeme_Grant 25-Jul-17 0:25am    
Have you set breakpoints on both the client (android app) and server (asp.net? webapp) and stepped through the process to see where it is failing?
* Does the server get the request from the client?
* Is the request correctly formatted and contains correct values?
* What is the server returning?
* What is the Client receiving from the server?
* Does the data received at the client match the data sent by the server?

If you are not familiar with using the Debugger, here is a great getting started video: Basic Debugging with Visual Studio 2010 - YouTube[^]
Koppula Ravi 25-Jul-17 5:14am    
1. No
2. The requested input is JSON formate, thats is 100% correct. i pass the same input through postman services its working fine.
3. its not calling the server.
i fallow the below site for implementation:
https://developer.xamarin.com/guides/xamarin-forms/cloud-services/consuming/rest/

Please help me out from this issue,if any solutions let me know.
Advance tx
Graeme_Grant 25-Jul-17 5:41am    
I would remove your phone number otherwise scammers will be calling you night and day!

http://localhost is a [local only] loopback service. The android emulator or phone is talking to itself, and not your dev server. You need to use the IP address of the web server pc.
Koppula Ravi 25-Jul-17 11:14am    
i will try with ip address by tomorrow, and if works my luck.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900