Forum Xamarin.Forms

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Xamarin.Forms to add Body using Http GET verb

adboy9696adboy9696 Member ✭✭

As I have tried to send data in HTTP GET verb from Postman Here is the screenshot which I am trying to achieve

[Postman][1]

As data is received using the above process sending with the JSON Body.
I have also sent the Bearer Token in the Authorisation as well.

As I am trying to achieve the same process in Xamarin as given Below.

var accesstoken = "S2UvmMMX9W71VQICZ9066raOAsqcH0l0XjNbQeAwBPZeke5lE-SSlRqiSRcsfUWK84YCGb145fSdpB6fctRtTebiTCNNLCWDbmxJei6rBYmrxABRrQQIcrVfKKo-I2i9qm1R0hnaJhIIQYyN4VyASgFc6fVowS9ZXhF1Ck8acP0LIm31_qIh4O_MP8Upd2FxMWfKnG-QXdUOEO87FSiZVNn_ytu_yv_YIgpkt_zScbrF5FAflU4PyaRhVuhe2Wt4T9fD8-q0O_uVp_RKG70Dc29Sigub3FmzULnCVV3cAAQ34Ql88ROm_IlJLlLJCwBEzdcOsTJqZSSAJYaJLB6GTG1gVzA5JIvR5ppTALROB8OlSbSCxay91wTXHBud9vxS0fbqjD-Tjaua_IHPmd7sJgVnTpcTBEjwCRYb3j3eWcGqCdKMq4Lvq9NNlEwS1xiR";
var http = new HttpClient();
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accesstoken);
http.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
http.DefaultRequestHeaders.Add("MethodStatementId", "0e175b05-8988-4a5c-9e5f-26ba606d226d");
var response = await http.GetAsync("http://dev.optimaldigitech.com:7091/api/MethodStatement/GetMethodStatement");

So How can I send the same JSON body with the Xamarin.Forms as only I have worked with GET API with no JSON Body.

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    We should avoid to send body with get request , the best solution is to switch to Post request in your backend .

    If you still want to use Get method , try the following steps

    1. Take the JSON object and convert it to string .

    2. Take the string and encode it in Base64.

    3. Append it to the URL .

    4. Reverse the process. decode and parse it into an object.


    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

Sign In or Register to comment.