Xamarin.Forms to add Body using Http GET verb

Akshay Dixit 21 Reputation points
2021-01-05T15:21:02.947+00:00

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

Postman

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.<br>
As I am trying to achieve the same process in Xamarin as given Below.<br>

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");

The following I have used for Reference below. <br>
https://forums.xamarin.com/discussion/104527/http-get-with-parameters<br>
https://www.c-sharpcorner.com/article/how-to-fetch-data-from-web-api-using-xamarin-forms/

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.

Developer technologies | .NET | Xamarin
Developer technologies | C#
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ángel Rubén Valdeolmos Carmona 611 Reputation points
    2021-01-05T15:49:13.507+00:00

    To my knowledge, to pass parameters by body is through post. You can use refit:
    https://github.com/reactiveui/refit

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.