首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >卷曲响应"200",GetAsync "406“

卷曲响应"200",GetAsync "406“
EN

Stack Overflow用户
提问于 2017-03-15 23:59:22
回答 1查看 553关注 0票数 0

我正试图从rails api中获得Xamarin表单应用程序的订单列表。

以下是我的Xamarin应用程序中返回“406”的代码:

代码语言:javascript
复制
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形式运行时返回以下内容:

代码语言:javascript
复制
[{"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"}]

我哪里出问题了?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-16 02:20:04

HTTP 406是“不可接受”的代码,这意味着您的HttpClient没有被正确地配置为从服务器接收有效负载。您需要将标题配置为正确的内容类型。

另见:什么是HTTP中的“406-不可接受的响应”?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42822964

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档