使用httpwebrequest登录网站 [英] login to website with httpwebrequest

查看:58
本文介绍了使用httpwebrequest登录网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我需要登录Fileserve.com的帮助,
我想进入登录背后的特定页面,

您能否看到以下代码错误:

Hello,
I need help loging into Fileserve.com,
I want to get to a specific page behind the login,

can you see an error with this code:

CookieContainer cookieContainer = new CookieContainer();
                    string html;
                    string loginData = "POSTDATA=loginUserName" + usrnm + "&loginUserPassword=" + pswrd + "&autoLogin=on&&ppp=102&loginFormSubmit=Login";

                    // First hit the login page
                    HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://fileserve.com/index.php");
                    req.CookieContainer = cookieContainer;
                    req.Method = "POST";
                    req.ContentType = "application/x-www-form-urlencoded";
                    ASCIIEncoding encoding = new ASCIIEncoding();
                    byte[] loginDataBytes = encoding.GetBytes(loginData);
                    req.ContentLength = loginDataBytes.Length;
                    Stream stream = req.GetRequestStream();
                    stream.Write(loginDataBytes, 0, loginDataBytes.Length);
                    stream.Close();
                    HttpWebResponse res = (HttpWebResponse)req.GetResponse();

                    // Packe den Content der Seite die hinter der Authenifizierung liegt
                    req = (HttpWebRequest)HttpWebRequest.Create("http://fileserve.com/file-manager.php");
                    req.CookieContainer = cookieContainer;
                    req.Method = "GET";
                    res = (HttpWebResponse)req.GetResponse();
                    StreamReader sr = new StreamReader(res.GetResponseStream());
                    html = sr.ReadToEnd();
                // richTextBox1.Text = html;



我只获得登录页面而不是我想要的页面,我使用篡改来获取Post Parameters&值.

对于那些了解jdownloader(用Java编写的Filehosting应用)的人,我看了一下那里的fileserve插件,并尝试将我的logindata更改为与jdownloader数据相等.




I only get the login page not the one I want,I used Tamper to get the Post Parameters & Values.

for those who knows jdownloader (Filehosting app written in Java), I took a look at the fileserve plugin there and tried to change my logindata to equal it with the jdownloader data


setBrowserExclusive();
       br.setFollowRedirects(true);
       br.postPage("http://fileserve.com/login.php", "loginUserName=" + Encoding.urlEncode(account.getUser()) + "&loginUserPassword=" + Encoding.urlEncode(account.getPass()) + "&autoLogin=on&loginFormSubmit=Login");
       br.getPage("http://fileserve.com/dashboard.php");
       String accType = br.getRegex("<h5>Account type:</h5>[\r\n ]+<h3>(Premium|Free)</h3>").getMatch(0);




现在loginData看起来像这样:




now loginData looks like this:

"loginUserName=" + usrnm + "&loginUserPassword=" + pswrd + "&autoLogin=on&loginFormSubmit=Login";










and


(HttpWebRequest)HttpWebRequest.Create("http://fileserve.com/login.php");




仍然没有成功,




still no success,
maybe I''m missing something?

推荐答案

要测试错误类型,您需要包括System.Web命名空间中的HttpResponse对象. HttpResponse具有StatusCode属性.根据该值,可以确认错误类型.
100继续
200 OK
201已创建
300种选择
301永久移动
302找到
400错误的请求
401未经授权
403 Forbidden
找不到404

To test the error type, you need to include HttpResponse object from System.Web namespace. HttpResponse has StatusCode property. Based on the value, you can confirm the error type.
100 Continue
200 OK
201 Created
300 Multiple Choices
301 Moved Permanently
302 Found
400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found

protected void Page_Load(object sender, EventArgs e)
{
    switch (Response.StatusCode)
    {
        case 100 : ....; break;
        case 200 : ....; break;
        case 300 : ....; break;
        ........
    }
}


这篇关于使用httpwebrequest登录网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆