Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

What's wrong with my HttpWebRequests?

Code
HttpWebRequest peticionGalleta = (HttpWebRequest)WebRequest.Create("twitter.com/sessions");
            peticionGalleta.ProtocolVersion = HttpVersion.Version11;
            peticionGalleta.Method = "POST";
            peticionGalleta.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
            peticionGalleta.ContentLength = 238;
            peticionGalleta.ContentType = "application/x-www-form-urlencoded";
            peticionGalleta.Host = "twitter.com";
            peticionGalleta.Referer = "twitter.com/login";
            peticionGalleta.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0";

            string postData = "session%5Busername_or_email%5D=" + textBox1.Text + "&session%5Bpassword%5D=" + textBox2.Text + "&remember_me=1&redirect_after_login=";
            byte[] byteArray = Encoding.UTF8.GetBytes(postData);

            StreamWriter sw = new StreamWriter(peticionGalleta.GetRequestStream());
            sw.Write(postData, 0, byteArray.Length);
            sw.Close();

            HttpWebResponse respuestaGalleta = (HttpWebResponse)peticionGalleta.GetResponse();
            StreamReader lectorGalleta = new StreamReader(respuestaGalleta.GetResponseStream());

            string html = lectorGalleta.ReadToEnd();

            MessageBox.Show(html.ToString());

The messagebox doesn't display anything (The links are fine, I just can't post them fully on HF)
I'm not dealing with this kind of method, but, isn't it an async method?
(May 27, 2016 11:32 AM)Sakuto Wrote:  I'm not dealing with this kind of method, but, isn't it an async method?

Hey man its a spanish website that tought people on how to do it, not sure if its the best way, where and how do u think I should learn? I wanna make bots for twitter... Thanks🤝
(May 27, 2016 11:32 AM)Sakuto Wrote:  I'm not dealing with this kind of method, but, isn't it an async method?

Nothing in his code is asynchronous at all.


But why do you have a GET variable that isn't assigned?
Code
&redirect_after_login=

And why are you hardcoding ContentLength as 238?
Code
peticionGalleta.ContentLength = 238;

^ You have no idea the length of the textbox inputs at compile time, so that is silly... :S

You don't know what you're doing and once you get into authentication you'll be lost.
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]
Yes DeadLock is right, well other than whyen he said it was GET variables. It's a POST variable since the method is POST.

Also op, don't set the content length, the webrequest will set it for you automatically after you write the data to the request stream.

Also, the main reason yours isn't working is because you most likely haven't made an initial request to gather the session cookies. Which you should include in the subsequent request.
Ahh, I got threads mixed up. Was reading another one where some guy wanted to send a bunch of threaded GET requests in C.
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]
(May 27, 2016 03:12 PM)+Haze Wrote:  Yes DeadLock is right, well other than whyen he said it was GET variables. It's a POST variable since the method is POST.

Also op, don't set the content length, the webrequest will set it for you automatically after you write the data to the request stream.

Also, the main reason yours isn't working is because you most likely haven't made an initial request to gather the session cookies. Which you should include in the subsequent request.

Where do you think I should learn about HttpWebRequests? Thanks
First you have to understand HTTP. From there it should be fairly easy to learn the .NET classes.
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by raider101Aug 15, 2015 04:01 PM 0 112 Aug 15, 2015 04:01 PM
Last Post: raider101
[.NET] by PunkbastardMay 18, 2015 09:08 PM 5 448 May 18, 2015 09:08 PM
Last Post: SIM-1676753
[C#] by Ampix0Apr 3, 2015 04:52 PM 5 204 Apr 3, 2015 04:52 PM
Last Post: LanMan