开发者

To receive URL after change

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; r开发者_如何转开发v: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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜