locked
Pass values from one APIController to another RRS feed

  • Question

  • User-375223641 posted

    Hello,

    I have a web API that receives data values from Facebook app and save these data to a MySQL Database. I want to pass the Facebook user ID to another API controller to pass it back to a mobile app (Cordova). I don't want to use session values. 

    Please advice 

    Saturday, June 24, 2017 6:17 PM

Answers

  • User-832373396 posted

    Hi elshorbagy ,

    I suggest that you could use HttpClient to call another APIController at API Controller.

    HttpClient client = new HttpClient();
    client.BaseAddress = new Uri("http://localhost/yourwebapi");
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    HttpResponseMessage response = client.GetAsync("api/getobjects").Result;
    if (response.IsSuccessStatusCode)
    {
        var data = response.Content.ReadAsAsync<IEnumerable<YourClass>>().Result;
    }
    else
    {
        //Something has gone wrong, handle it here
    }

    Here is the article on how to use HttpClient in details : https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client

    Hope this helps.
    With Regards,

    Jolie

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 27, 2017 7:13 AM