tags:

views:

47

answers:

2

After authorisation on www.vkontakte.ru through ie8 me spans on page: www.vkontakte.ru/MyPage. But I cannot receive www.vkontakte.ru/MyPage through a code

        HttpWebRequest authRequest = (HttpWebRequest)WebRequest.Create(new Uri("http://vkontakte.ru/login.php", UriKind.Absolute));
        authRequest.CookieContainer = new CookieContainer();
        authRequest.AllowAutoRedirect = false;
        string param = string.Format("email={0}&pass={1}&expire=1", HttpUtility.UrlEncode("---"), HttpUtility.UrlEncode("---"));
        authRequest.Method = "POST";
        authRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)";
        authRequest.ContentType = "application/x-www-form-urlencoded";
        authRequest.ContentLength = param.Length;
        authRequest.GetRequestStream().Write(Encoding.GetEncoding(1251).GetBytes(param), 0, param.Length);

HttpWebResponse authResponse = (HttpWebResponse)authRequest.GetResponse(); 
listBox1.Items.Add(authRequest.Address);

Returns http://vkontakte.ru/ instead of www.vkontakte.ru/MyPage =( HttpContext.Current.Request.Url.AbsoluteUri - can help? help me!

+2  A: 

You forgot to close the request stream.

You should write the following:

using (Stream requestStream = authRequest.GetRequestStream())
using (StreamWriter writer = new StreamWriter(requestStream, Encoding.GetEncoding(1251))
    writer.Write(param);

Also, you should run Fiddler check what the request and response look like.

SLaks
A: 

I only wish to receive url...Did not think that it so difficult I could not understand with Fiddler... =\

Dobermann