开发者

How to Send a Web Request to Log Out?

开发者 https://www.devze.com 2023-02-18 01:45 出处:网络
I want to log out from page using webclient. This is my code for login and site downloading. public bool LogIn(string loginName, string password)

I want to log out from page using webclient.

This is my code for login and site downloading.

public bool LogIn(string loginName, string password)
{
    try
    {
        NameValueCollection postData = new NameValueCollection();
        postData.Add("login", loginName);
        postData.Add("password", password);

        // Authenticate
        _webClient.UploadValues("http://rapideo.pl/login.php", postData);
        //string temp = _webClient.DownloadString("http://rapideo.pl/lista");
    }
    catch
    {
        return false;
    }
    _loggedIn = true;
    _loginName = loginName;
    return true;
}

class WebClientEx : WebClient
{
    public CookieContainer CookieContainer { get; private set; }

    public WebClientEx()
    {
        CookieContain开发者_JS百科er = new CookieContainer();
    }

    protected override WebRequest GetWebRequest(Uri address)
    {
        var request = base.GetWebRequest(address);
        if (request is HttpWebRequest)
        {
            (request as HttpWebRequest).CookieContainer = CookieContainer;
        }
        return request;
    }
}

In order to logout I only need to open that page in browser:

http://rapideo.pl/wyloguj

I know how to download sourcecode of the page after login. But how can I send http request to logout? I don't want do get response or sourcecode of that page. i just want to sent request.


As a sanity check, have you already tried doing a WebRequest.DownloadString("http://rapideo.pl/wyloguj") and then just discarding the returned data?

If that is not working, one thing to try would be to look at the request/response messages in a tool like Fiddler to see what exactly is going over the wire when you log out via the browser versus programmatically.

Also, as a general aside, it looks like the user's name and password are being sent in the clear as part of the login. Not sure if there is an HTTPS login endpoint available for that site but that would be something to look into.

0

精彩评论

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