简体   繁体   中英

C# HttpClient 307 Destiny 2 SearchUser API

I am working on a library for the Destiny 2 API and I am running into a problem at this spot. I wrote an extension for the HttpClient.GetAsync so that I can do HttpClient.GetAsync<T> and I am finding that in this extension I am not getting a success message because I get a

307 Temporary Redirect

I have run this same API request into Postman using my same api key and same path request and Postman doesn't get an error.

Extension Code:

public async static Task<T> GetAsync<T>(this HttpClient Web, String Path)
        {
            var result = await Web.GetAsync(Path);
            if (result.IsSuccessStatusCode)
            {
                var body = await result.Content.ReadAsStringAsync();
                return JsonConvert.DeserializeObject<T>(body);
            }
            else
            {
                return default(T);
            }
        }

HttpClient Creation at creation of root ApiClass:

private HttpClient _Web { get; set; } = new HttpClient(new HttpClientHandler()
        {
            AllowAutoRedirect = true
        });

So after beating my head for awhile I found that I was passing this string string path = $"User/SearchUsers?q={q}"; when it wanted this string string path = $"User/SearchUsers/?q={q}"; notice the slash after SearchUsers... Their API I think is just misconfigured and that was very annoying..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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