0

I'm attempting to get a list of orders for my Xamarin Form application from my rails api.

Here is the code in my Xamarin Application that returns a "406":

async void UpdateOrders(string token)
    {
        // clear all the previous orders 
        orders.Clear();

        var client = new HttpClient();
        string url = "http://localhost:3000/api/orders?access_token=" + token;
        Debug.WriteLine(url);

        var response = await client.GetAsync(url);

        //response.EnsureSuccessStatusCode(); 

        if (!response.IsSuccessStatusCode)
        {
            Debug.WriteLine("this didn't work");
            //var ex = CreateExceptionFromResponseErrors(response);
            //throw ex;
        }
        else
        {
            // get the orders from the JSON 
            var orderItems = JsonConvert.DeserializeObject<List<Order>>(response.ToString());

            // add all the orders to the page 
            orders = new ObservableCollection<Order>(orderItems);
        }
    }

url = "http://localhost:3000/api/orders?access_token=03642494d1631421a8b49a21085b53907e8498794c0dcacc61c7b4eefbf1b7eb"

** on a side-note the CreateExceptionFromResponseErrors line throws an error?

The same url above returns the following when I run it in CURL:

[{"id":1,"invoice":"HALP","description":"TESTING","weight":100.0,"length":48,"width":48,"height":48,"account_id":1,"driver_id":null,"status":"preview","account_quote":576,"driver_quote":432,"created_at":"2017-03-11T17:18:40.418Z","updated_at":"2017-03-11T17:18:40.418Z","driver_rating":5,"account_rating":5,"guid":"cfd12c84-b260-440c-a21a-7a8aab44b5ac"}]

Where am I going wrong?

Edie W.
  • 667
  • 2
  • 9
  • 24

1 Answers1

0

HTTP 406 is the code for "not acceptable", meaning that your HttpClient is not properly configured to receive the payload from the server. You will need to configure your header for the correct content type.

See also: What is “406-Not Acceptable Response” in HTTP?

Community
  • 1
  • 1
ellison
  • 69
  • 1
  • 3