matomo-org / piwik-dotnet-tracker

C# API client SDK for the Piwik Tracking API
BSD 3-Clause "New" or "Revised" License
74 stars 47 forks source link

400 error from server due to an invalid IP when using on localhost #81

Open epos opened 3 years ago

epos commented 3 years ago

Hi,

Thank your for the project.

On an ASP.NET 4.5.2 MVC project running in IIS Express on my local machine, I get a 400 error from the Matomo 4.1.0 server :

https://piwik.<our domain>.com/piwik.php?idsite=11&rec=1&apiv=1&r=250779&cip=::1&_idts=1611940818&_id=7b2be05759a2bc7d&url=http%3a%2f%2flocalhost%2fdefault.aspx&e_c=mycat3&e_a=myact3

The 400 error is due to the cip=::1 query string value. When I remove cip from the query string, all goes well. It looks like the server rejects what it considers as an invalid IP value.

The problem likely lies in the PiwikTracker constructor :

            _ip = HttpContext.Current?.Request?.UserHostAddress ?? string.Empty;

Indeed, UserHostAddress returns ::1 on my machine, using IIS Express with .NET 4.5.2.

Best regards.