我正在尝试从rails api获取我的Xamarin表单应用程序的订单列表。
以下是我的Xamarin应用程序中返回“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);
}
}
**旁边注意CreateExceptionFromResponseErrors行是否会抛出错误?
当我在CURL中运行时,上面的同一个url返回以下内容:
[{"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"}]
我哪里错了?