gpt4 book ai didi

c# - 如何使用 C# 远程对 Stack Overflow 帖子投反对票?

转载 作者:太空狗 更新时间:2023-10-29 23:55:01 29 4
gpt4 key购买 nike

<分区>

我可能正在尝试做一些不可能或非常困难的事情,但无论如何我都想尝试一下。我一直在努力编写一个程序,可以自动为我对 Stack Overflow 帖子投反对票。

因此,我合乎逻辑的第一步是找出当我按下反对票按钮时幕后发生的事情。我使用了 HTTP 网络分析器来查看浏览器如何与我想要否决的服务器通信。这就是它向我展示的内容。

Downvote details

然后我想,如果我编写一个 C# 程序发送一个 HTTP 请求,我应该能够远程对它投反对票,该程序发送的 HTTP 请求与我按下投反对票按钮时发送的请求相同。所以我想到了这个:

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();

有一些标题不允许我写。对于 header AcceptRefererUser-AgentConnection,它会抛出如下错误:

This header must be modified using the appropriate property or method.

Host header 导致此错误:

The 'Host' header cannot be modified directly.

我只是注释掉了导致问题的 header ,乐观地希望它仍然可以正常工作,但我从服务器返回了这条消息

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

"Success":false 似乎表明它没有成功否决该帖子,我转到该页面,它的投票数与我运行程序之前相同.换句话说,我的程序没有运行。

有谁知道我是否走在正确的道路上,我可以做些什么来让它发挥作用,或者是否有可能让它发挥作用?

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com