How to send parameter in REST api in xamarin.forms ?
I have created REST API Project in xamarin using PCL.
When I call Simple REST api using Below code in Xamarin.forms (Portable Class Library) then I have Successfully receive json Response.
using (var cl = new HttpClient()) { var result = await cl.GetStringAsync("http://192.168.1.100/apps/jara/web/api/user/test"); jsonResponseClass des = JsonConvert.DeserializeObject<jsonResponseClass>(result); lbl1.Text = des.code + " " + des.status + " " + des.message; } public class jsonResponseClass { public string code { get; set; } public string status { get; set; } public string message { get; set; } }
Using above code I got a response
{ code: 200, status: "ok", message: "hello" }
REST API response type is JSON and type is POST
Now, I want to call below Login Api using paramater.
http://192.168.1.100/apps/jara/web/api/user/login
Paramater : email_id and Password
this api success response type is....
{ code: 200, status: "Success", User: { userid: 126, token: "d154s4d54s654df5s4df56s4df564s5df4", email: "[email protected]", mobile_number: "9898989898" }, message: "Successfully logged in" }
What can i do ?
Answers
Finally i can do this using below code....
This code helpful for Calling REST API with Parameter
Thank you...
Thanks, it's working for me.
@Shahabuddin Vansiwala please can I get the full project, am having issues with mine
@AmayindiLynn
What issue have you got ?
To pass parameter in a simple manner (IMO) I just use a simple DTO with fields I want to send as parameter, serialize it and done.
Don't forget the JsonProperties. Exemple with a login DTO.
@Umar3x An error occurred while sending the request ---> System.Net.WebException: Error: ConnectFailure (Connection timed out) ---> System.Net.Sockets.SocketException: Connection timed out
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x000b6] in :0
at System.Net.WebConnection.Connect (System.Net.HttpWebRequest request) [0x0016d] in :0
@Umar3x
1. An error occurred while sending the request ---> System.Net.WebException: Error: ConnectFailure (Connection timed out) ---> System.Net.Sockets.SocketException: Connection timed out
2. at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x000b6] in :0
3. at System.Net.WebConnection.Connect (System.Net.HttpWebRequest request) [0x0016d] in :0
@Umar3x I am receiving a:
ERROR An error occurred while sending the request
System.Net.Http.HttpRequestException: An error occurred while sending the request ---> System.Net.WebException: Error: ConnectFailure (Connection timed out) ---> System.Net.Sockets.SocketException: Connection timed out
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x000b6] in :0
at System.Net.WebConnection.Connect (System.Net.HttpWebRequest request) [0x0016d] in :0
@Umar3x I am receiving a:
ERROR An error occurred while sending the request
System.Net.Http.HttpRequestException: An error occurred while sending the request ---> System.Net.WebException: Error: ConnectFailure (Connection timed out) ---> System.Net.Sockets.SocketException: Connection timed out
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x000b6] in :0
at System.Net.WebConnection.Connect (System.Net.HttpWebRequest request) [0x0016d] in :0
@Umar3x I am receiving a:
ERROR An error occurred while sending the request
System.Net.Http.HttpRequestException: An error occurred while sending the request ---> System.Net.WebException: Error: ConnectFailure (Connection timed out) ---> System.Net.Sockets.SocketException: Connection timed out
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x000b6] in :0
at System.Net.WebConnection.Connect (System.Net.HttpWebRequest request) [0x0016d] in :0
@Umar3x
ERROR An error occurred while sending the request
System.Net.Http.HttpRequestException: An error occurred while sending the request ---> System.Net.WebException: Error: ConnectFailure (Connection timed out) ---> System.Net.Sockets.SocketException: Connection timed out
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x000b6] in :0
at System.Net.WebConnection.Connect (System.Net.HttpWebRequest request) [0x0016d] in :0
Very helpful!
@ShahabuddinVansiwala
i was looking for this code since yesterday...working great...thank you so much...