当我使用邮递员时,一切似乎都很好,我得到了正确的响应,仅使用代码会使我出现错误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;
}
我仅在邮递员中得到回复,使用相同的url和access_token删除了jsut,然后出于隐私考虑,您能解释一下这是怎么回事以及缺少的部分!
答案 0 :(得分:0)
谢谢大家,我使用的是不需要的授权标头,我的访问令牌直接传递到请求正文中,谢谢,现在问题已解决