我正试图从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);
}
}url = "token=03642494d1631421a8b49a21085b53907e8498794c0dcacc61c7b4eefbf1b7eb“
**在旁边-注意CreateExceptionFromResponseErrors行抛出了一个错误?
上面相同的url在以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"}]我哪里出问题了?
发布于 2017-03-16 02:20:04
HTTP 406是“不可接受”的代码,这意味着您的HttpClient没有被正确地配置为从服务器接收有效负载。您需要将标题配置为正确的内容类型。
https://stackoverflow.com/questions/42822964
复制相似问题