Harsha Gangari
Harsha Gangari

Reputation: 11

How to send an object with out class from one API to another API?

I am writing two API's, Api 1 and Api 2. I have an object of type "dynamic" in my Api 1. I am trying to send this object to Api 2. Here is my code:

public IActionResult processPensionInput([FromBody]dynamic inputFromPensionerBody)
{

    using(var askPensionDisbursement = new HttpClient())
    {
        var jsonstring = JsonConvert.SerializeObject(inputFromPensionerBody);
        askPensionDisbursement.BaseAddress = new Uri("http://localhost:51549/api/PensionDisbursements/");
        var responseTalk = askPensionDisbursement.GetAsync("calculate?inputFromPensioner="+ jsonstring);
        responseTalk.Wait();

        return Ok(responseTalk.Result);
        int code = (int)responseTalk.Result.StatusCode;
        if(code==10)
        {
            var readTask = responseTalk.Result.Content.ReadAsStringAsync();

            return Ok("Okay");
        }

        return Ok("Not okay");
    }
}

The other API's code is

public IActionResult calculatefromdetails(dynamic inputFromPensioner/*,dynamic serviceCharge*/)
{
    StatusCodeResult flag = new StatusCodeResult(21);
    using (var response = new HttpClient())
    {
        //some loooong code here...
    }
    return new StatusCodeResult(10);
}

But the problem arises in the first API itself, where in the Postman, the output is 415 media type not found. How to send the object from one API to another?

Upvotes: 0

Views: 198

Answers (1)

Mody
Mody

Reputation: 11

You can't implement a json string in .GetAsync in the api 1.

Upvotes: 1

Related Questions