OK i found what was going on here... When the statuscode obtained in the response is "Notfound" or "Unauthorized" a Webexception is thrown so if you want to check the property of the response you need to do it inside the catch of the exception...It seems this is only the case on Windows phone... Here is the code which worked for me :
private void GetResponseIdentificationNT(IAsyncResult MyresponseAsync)
{
HttpWebRequest request = (HttpWebRequest)MyresponseAsync.AsyncState;
if (request != null)
{
try
{
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(MyresponseAsync);
if (response.StatusCode == HttpStatusCode.OK)//l'authentification a réussi
{
if (event_Authorized != null)
event_Authorized.Invoke();
}
}
catch (WebException we)
{
HttpWebResponse response = (HttpWebResponse)we.Response;
if (response.StatusCode==HttpStatusCode.Unauthorized)
{
if (event_Unauthorized != null)
event_Unauthorized.Invoke();
}
else if (response.StatusCode == HttpStatusCode.NotFound)//Server error
{
if (event_NotFound != null)
event_NotFound.Invoke();
}
}
catch (Exception ex)
{
throw new UnknowException(ex.Message);
}
}
}