繁体   English   中英

获取服务器错误 500,“内部服务器错误”,但在 Postman 上工作正常,在 c# 中使用 httpclient

[英]getting server error 500, 'Internal Server Error', but works fine on Postman, using httpclient in c#

当我使用 postman 时,一切似乎都很好,我得到了正确的响应,只有使用代码才能得到错误 500,我在这里发布问题之前经常检查,谢谢

 string host = "removed for privacy";
        string access_token = "removed for privecy"
        int profileId = 25; 
        string getTemplate = "/profiles/{0}/orders?order_status=new";
        string putTemplate = "/profiles/{0}/orders/{1}";
        string getPath;
        string putPath;

        HttpClient client = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate });
        
        public User()
        {
            client.BaseAddress = new Uri(host);

            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", access_token);

            getPath = string.Format(getTemplate, profileId);
            Uri.EscapeUriString(getPath);
        }

        public List<Order> GetNewOrders()
        {

            Console.WriteLine(client.BaseAddress + getPath);

            List<Order> orders = null;
            HttpResponseMessage response = client.GetAsync(client.BaseAddress + getPath).Result;
            Console.WriteLine(response);

            if (response.IsSuccessStatusCode)
            {

                orders = response.Content.ReadAsAsync<List<Order>>().Result;               
            }
            else
            {
                response.EnsureSuccessStatusCode();
            }
            return orders;
        }
  

我只在 postman 中得到回复,使用相同的 url 和 access_token 我只是为了隐私而删除了,你能解释一下它有什么问题以及缺失的部分在哪里!

谢谢大家,我正在使用授权 header 不需要它,我的访问令牌直接传递到请求正文中,谢谢问题现在解决了

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM