Po zalogowaniu proces logowania przy użyciu Firebug widzę, że to jest jak toWebClient nie oznacza automatycznie przekierować
POST //The normal post request
GET //Automatically made after the login
GET //Automatically made after the login
GET //Automatically made after the login
Przy składaniu wniosku Post używając mojego kodu poniżej nie dokona automatycznego żądania GET że przeglądarkach robić.
MY WebClient Handler
using System;
using System.Net;
namespace Test
{
class HttpHandler : WebClient
{
private CookieContainer _mContainer = new CookieContainer();
protected override WebRequest GetWebRequest(Uri address)
{
var request = base.GetWebRequest(address);
if (request is HttpWebRequest)
{
(request as HttpWebRequest).CookieContainer = _mContainer;
}
return request;
}
protected override WebResponse GetWebResponse(WebRequest request)
{
var response = base.GetWebResponse(request);
if (response is HttpWebResponse)
_mContainer.Add((response as HttpWebResponse).Cookies);
return response;
}
public void ClearCookies()
{
_mContainer = new CookieContainer();
}
}
}
pomocą kodu
private static async Task<byte[]> LoginAsync(string username, string password)
{
var postData = new NameValueCollection();
var uri = new Uri(string.Format("http://{0}/", ServerName));
postData.Add("name", username);
postData.Add("password", password);
return await HttpHandler.UploadValuesTaskAsync(uri, postData);
}
Gdy próbuje śledzić połączenia mojego wniosku, że robi tylko żądanie POST, a nie reszta żądań GET. [ZOSTANIE AUTOMATYCZNIE WYKONANE W PRZEGLĄDARCE]
Czy to też nie działa w wersji synchronicznej? Z AllowAutoRedirect, oczekiwałbym, że to zadziała ... być może jest to problem z przekierowaniem z POST? –