views:

205

answers:

3

Hello,

I write a little Tool in C# with Visual Studio 2008.

My Problem:

I login to a website by HTTP-webrequest, I get an authentification cookie, thats all ok.

Than I make a new HTTP-webrequest and add the cookies from the first request to call the next page where i can see my personal data. I see that the cookies will associated with the second request if I debug it but if I check the network traffic I see that are no Cookies transmitted at the second request. I tried many possibilities to see why i dont work but i found nothing.

Does somebody have the same problem or know a solution? (Sorry for bad english)

A: 

Hello, here are the code from the two requests:

        //First Request to Login (work)
        CookieContainer _cookieContainer = new CookieContainer();

        HttpWebRequest _request1 = (HttpWebRequest)WebRequest.Create("http://uploaded.to/login");
        _request1.Method = "POST";
        _request1.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
        _request1.AllowAutoRedirect = false;
        _request1.CookieContainer = _cookieContainer;
        _request1.Referer = "http://uploaded.to/login";
        _request1.ContentType = "application/x-www-form-urlencoded";
        _request1.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)";
        _request1.Headers.Add("Keep-Alive", "115");

        string _postData = "email=1146209&password=rjadkia";
        byte[] _byteArray = Encoding.UTF8.GetBytes(_postData);
        _request1.ContentLength = _byteArray.Length;

        Stream _reqStream = _request1.GetRequestStream();
        _reqStream.Write(_byteArray, 0, _byteArray.Length);
        _reqStream.Close();

        HttpWebResponse _response1 = (HttpWebResponse)_request1.GetResponse();
        _response1.Close();




        //And the Second Request for the next site (dont work)

        HttpWebRequest _request2 = (HttpWebRequest)WebRequest.Create("http://uploaded.to/login?coo=1");
        _request2.Method = "GET";
        _request2.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
        _request2.ContentType = "application/x-www-form-urlencoded";
        _request2.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)";
        _request2.Referer = "http://uploaded.to/login";
        _request2.Headers.Add("Keep-Alive", "115");
        _request2.CookieContainer = _cookieContainer

        HttpWebResponse _response2 = (HttpWebResponse)_request2.GetResponse();
        _response2.Close();

This is the easiest code, i tried many other methods, for example with other headers or to save the cookies separate and add it manual to the second request but nothing worked.

There would be a third request and then its finished but thats not important now because I stuck on the second.

(Its a free account, so dont worry about the login information)

Thanks in advance!

Collin Peters
A: 

Hi Collin.

I am having the same problem. Have you resolved this mater?

Best regards.

Ragnar Hólm Gunnarsson
No, I unfortunately still depends on the problem and apparently no one can help me.
Collin Peters
A: 

Does nobody have an idea or an suggestion?

Collin Peters