tparviainen / clashofclans

A .NET library for accessing Supercell's Clash of Clans API.
https://tparviainen.github.io/clashofclans/
MIT License
23 stars 1 forks source link

ClashOfClansException on ClashOfClansApi.Clans.GetAsync(ClanTag) #1

Closed lukeparsons closed 5 years ago

lukeparsons commented 5 years ago

'At least one filtering parameter must exist: badRequest'

ClashOfClansException message when searching a clan by tag using .GetAsync

How to reproduce

try-catch the .GetAsync function inside a async Task and print to console the clash of clans exception

Versions

tparviainen commented 5 years ago

I just tried exactly the above repro steps and I wasn't able to repro.

Clans API has two GetAsync methods:

Task<SearchResult> GetAsync(QueryClans query);
Task<Clan> GetAsync(string clanTag);

The latter one (GetAsync(string clanTag)) is the one where you provide a clan tag and it gives the clan information. The former one (GetAsync(QueryClans query)) is where you provide a QueryClans object that has properties to filter the search results. If QueryClans is provided empty in API call then Supercell API returns a bad request to caller with next information:

Content: {"reason":"badRequest","message":"At least one filtering parameter must exist"}

That is a valid error because QueryClans must always have at least one filtering criteria defined.

If you could share a sample solution with this problem that I can just open in VS and get into the state, it would be great for investigating.

lukeparsons commented 5 years ago

Thank you for your reply. Attached is an example project which causes the exception when run.

ConsoleApp.zip

tparviainen commented 5 years ago

Thanks for providing the project to investigate this more. I found the issue causing this behavior. It seems that net461 does not URL encode hash (#) character automatically whereas netcoreapp2.2 implementation of HttpClient will do it.

I changed the implementation of the library to URL encode hash character always and now it seems to work properly also in net461. I will push a commit soon to fix this issue and release 3.0.5 version of the NuGet package with the fix.

Thanks for reporting this issue!