रीडायरेक्ट नहीं करता है जब Firebug का उपयोग कर मैं देख यह इसWebClient स्वचालित रूप से
POST //The normal post request
GET //Automatically made after the login
GET //Automatically made after the login
GET //Automatically made after the login
की तरह है कि जब नीचे यह स्वत: प्राप्त अनुरोधों ब्राउज़र है कि नहीं था मेरे कोड का उपयोग कर एक पोस्ट अनुरोध करने वाले प्रवेश प्रक्रिया प्रवेश करने करते हुए।
मेरी WebClient हैंडलर
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();
}
}
}
कोड
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);
}
का उपयोग करते हुए जब अपने आवेदन में यह केवल पोस्ट अनुरोध और नहीं मिल शेष अनुरोधों कर रहा है के कनेक्शन ट्रैक करने के लिए कोशिश कर रहा। [यह ब्रॉसर में स्वचालित रूप से बनाया गया है]
क्या यह सिंक्रोनस संस्करण में भी विफल रहता है? AllowAutoRedirect के साथ, मैं इसे काम करने की उम्मीद करता हूं ... संभवतः यह POST से पुनर्निर्देशित करने में एक समस्या है? –