Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Azure machine learning Rest api code breaks on execution

$
0
0

Hi, I cant figure out what is wrong in here as it keep failing, previously I was using same code in UWP. But now I want to execute it in Xamarin forms app. Please help? :( Here is my code....

public async void MachineLearning()
{
try
{
using (var client = new HttpClient())
{
var request = new
{
Inputs = new Dictionary<string, StringTable>() {
{
"User_Name_input",
new StringTable()
{
ColumnNames = new string[] {"User_Name", "Type"},
Values = new string[,] { {"Drake", "Celebrity" } }
}
},
},
GlobalParameters = new Dictionary<string, string>()
{
}
};

                const string key = "*****************************************************************************";
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", key);
                client.BaseAddress = new Uri("*****************************************************************");

                HttpResponseMessage response = await client.PostAsJsonAsync("", request).ConfigureAwait(false);


                if (response.IsSuccessStatusCode)
                {

                    string result = await response.Content.ReadAsStringAsync();
                    Rootobject obj = JsonConvert.DeserializeObject<Rootobject>(result);


                    string MyResult = (String.Format("{0}", obj.Results.User_data.value.Values[0][15]));

                    DisplayAlert(MyResult, MyResult, "OK");


                }
                else
                {

                    DisplayAlert("WARNING", "The request failed", "Ok");
                }



            }
        }
        catch (Exception e)
        {
            System.Diagnostics.Debug.WriteLine(e.ToString());
        }

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>