How can I remotely delete a message in C # from C #?

Maybe I'm trying to do something impossible or very difficult, but I still wanted to try. I was working on writing a program that can automatically reduce stack overflow entries for me.

So, my logical first step was to find out what happened behind the scenes when I pressed the downvote button. I used the HTTP network analyzer to find out how the browser interacts with the server I want to use. This is what he showed me.

Downvote details

Then I decided that I had to roll it off remotely if I wrote a C # program that would send an HTTP request identical to the one I sent when I clicked the downvote button. So I came up with this:

WebRequest req = WebRequest.Create("http://stackoverflow.com/posts/3905734/vote/3"); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; req.ContentLength = 37; req.Headers.Add("Request", "POST /posts/3905734/vote/3 HTTP/1.1"); req.Headers.Add("Accept", "application/json, text/javascript, */*; q=0.01"); req.Headers.Add("X-Requested-With", "XMLHttpRequest"); req.Headers.Add("Referer", "http://stackoverflow.com/questions/3905734/how-to-send-100-000-emails-weekly"); req.Headers.Add("Accept-Language", "en-us"); req.Headers.Add("Accept-Encoding", "gzip, deflate"); req.Headers.Add("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; MAAU)"); req.Headers.Add("Host", "stackoverflow.com"); req.Headers.Add("Connection", "Keep-Alive"); req.Headers.Add("Cache-Control", "no-cache"); req.Headers.Add("Cookie", "__utmc=140029553; __utma=140029553.1661295586.1330352934.1331336368.1331402208.44; __utmz=140029553.1331159433.33.7.utmcsr=meta.stackoverflow.com|utmccn=(referral)|utmcmd=referral|utmcct=/users/153008/cody-gray; __qca=P0-1737884911-1330352934366; usr=t=TJUTES9CakOu&s=f3MgHSwW2EWk; km_ai=91003; km_uq=; km_lv=x; km_ni=91003; __utmb=140029553.17.10.1331402208"); var requestMessage = Encoding.UTF8.GetBytes("fkey=abfd538253d7ca1e988f306ea992eda0"); var strm = req.GetRequestStream(); strm.Write(requestMessage, 0, requestMessage.Length); strm.Close(); var rep = req.GetResponse(); strm = rep.GetResponseStream(); var rdr = new StreamReader(strm); string responseFromServer = rdr.ReadToEnd(); Console.WriteLine(responseFromServer); rdr.Close(); strm.Close(); Console.Read(); 

There were some headlines that I would not write. For the Accept , Referer , User-Agent and Connection headers, he generated this error:

This title should be modified using the appropriate property or method.

and the Host header caused this error:

The host header cannot be changed directly.

I just commented on the headers that were causing the problems, optimistically hoping it would work anyway, but I got this message from the server

{"Success":false,"Warning":false,"NewScore":0,"Message":"","Refresh":false}

"Success":false , it seemed, indicated that he did not have time to start the message, and I went to the page, and he had the same vote count as before I started the program. In other words, my program did not work.

Does anyone know if I am on the right track, what can I do to make it work, or if it can even make it work?

+4
source share
1 answer

You may not consider this an answer, but I do it; what you are trying to do is considered system abuse. We do not provide an API for this for many reasons, and trying to reverse engineer something that is not part of the published API is ... unpleasant.

Thank you for placing your security cookies. Thus, I will click a button to withdraw you from SE to protect your account from abuse. You will be able to log in as usual.

We reserve the right to be frankly childish and childish if you insist on an attempt to abuse the system; we are always happy to introduce additional hoops and obstacles, an accidental change in the API, etc., if we believe that you are trying to do unpleasant things. Or simply suspend your account or block access to the network.

Let me summarize: we really do not want you to do this.

+23
source

Source: https://habr.com/ru/post/1400754/


All Articles