WindowsDevicePortalWrapper icon indicating copy to clipboard operation
WindowsDevicePortalWrapper copied to clipboard

HttpStatusCode 307 handling

Open haeberle opened this issue 8 years ago • 4 comments

Dear team

During testing I identified an topic that runs into an error by using the wrapper. I'm using the SampleWdpClient app and randomly during request to the device, the device responses a request with a 307 state code and the wrapper follows the redirected uri an gets an html page as answer. As result, the deserializer fails because the answer isn't an json string.

In the most of the request, the device answers the request with an 401, the httpclient sends the credentials and all works well. Except in some cases (all 2-4 times) the device answers with an 307 and the wrapper fails.

Do I have to configure the devices differently (I tested more than one with the same result) ? I'm using the last nuget version (0.9.5.1)

below the wireshark trace:

image

image

thanks a million.

haeberle avatar Dec 16 '17 13:12 haeberle

Hi @haeberle , are you using this against an IoT device? If so, we've identified the issue and are working to fix it in the WDP product itself.

The root cause here is that the .NET framework for HTTP purposefully sends the request without credentials, then responds with creds on a 401. Unfortunately the IoT Authenticator module in WDP counts cred-less requests as bad faith login attempts and ticks up a counter to mark whether they should be redirected to the login page.

hpsin avatar Dec 18 '17 17:12 hpsin

Hello @hpsin thanks a lot for the explanation. Yes, I'm using Win10 IoT on a raspberry.

I fixed it quick & dirty in GetAsync<..> by executing the request again in case the response status code is 307.

That helps as long no other clients request the page parallel as implemented in the WDP.

haeberle avatar Dec 18 '17 19:12 haeberle

Thanks! That's a good workaround. I'm going to leave this open until @namkedia confirms that the fix internally is checked in.

hpsin avatar Dec 18 '17 19:12 hpsin

Push for fix in trunk.

shiftrew avatar Oct 16 '19 08:10 shiftrew