接收更改后的 URL

发布于 2024-08-16 05:14:31 字数 1213 浏览 1 评论 0原文

通过 ie8 在 www.vkontakte.ru 上授权后,我的页面跨度为:www.vkontakte.ru/MyPage。但我无法通过代码接收 www.vkontakte.ru/MyPage

        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); 

返回 http://vkontakte.ru/ 而不是www.vkontakte.ru/MyPage =( HttpContext.Current.Request.Url.AbsoluteUri - 可以帮忙吗? 帮我!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

絕版丫頭 2024-08-23 05:14:31

您忘记关闭请求流。

您应该编写以下内容:

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

此外,您应该运行 Fiddler 检查请求和响应是什么样的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文