C# HttpClient 307 Destiny 2 SearchUser API

570 views Asked by At

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
        });
1

There are 1 answers

0
Bailey Miller On

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..