WebClient.DownloadString()时出现500错误

时间:2018-11-09 22:16:50

标签: c# httprequest html-parsing webclient

我正尝试使用c#解析html以获取site的所有比赛的接球率。

我正在将此代码用于另一个网站上的捕获匹配率,并且效果很好。

SELECT * FROM records WHERE html_id='i1481988552' /*The next 10 records after i1481988552 but how??*/

但是当我将网址更改为

Uri url = new Uri("https://1xbetm.mobi/LineFeed/Get1x2_VZip?sports=1&count=500&lng=tr&tf=1500000&tz=3&mode=4&country=190&getEmpty=true");
WebClient client = new WebClient();
string jsonOneXBetData = client.DownloadString(url);

我遇到500错误:(

我曾尝试使用Fiddler 4阅读此网站请求操作,但找不到正确的网址。

我尝试使用Wireshark。但是我不知道如何过滤本地请求并查看网址。

所以我不知道我该怎么办。。你能帮我吗?

1 个答案:

答案 0 :(得分:1)

尝试如下装饰请求标头:

Uri url = new Uri("https://1xbetm.mobi/LineFeed/Get1x2_VZip?sports=1&count=500&lng=tr&tf=1500000&tz=3&mode=4&country=190&getEmpty=true");
System.Net.WebClient client = new System.Net.WebClient();
client.Headers.Add ("user-agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko");

string jsonOneXBetData = client.DownloadString(url);

修改1: 对于其他网址,似乎还需要2个标头参数:

Uri url = new Uri("https://www.86tempobet.com?reloadlive=240671122&no_write_sess=1");
System.Net.WebClient client = new System.Net.WebClient();
client.Headers.Add ("user-agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko");
client.Headers.Add("method","POST");
client.Headers.Add("cookie","{cookie}");

string jsonOneXBetData = client.DownloadString(url);

修改2: 这是将响应作为json访问的完整请求:)

Uri url = new Uri("https://www.86tempobet.com?reloadlive=240671122&no_write_sess=1");
System.Net.WebClient client = new System.Net.WebClient();
client.Headers.Add ("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36");
client.Headers.Add("method","POST");
client.Headers.Add("cookie","visid_incap_1875943=C4HkVjo8RCCFldh593iChSbq6VsAAAAAQUIPAAAAAABzSYMXxV4TSKKZijRL24QX; incap_ses_277_1875943=ZnjKE7twmRYrT7s2YxvYAybq6VsAAAAAFdaEfL/KiNMUMywbnQeCNA==; GAMBLINGSESS=jfr3uadgl1ogv55c06ee6mvvs3fiv86p; nlbi_1875943=4NdhZ5rR80YChdm11QdqAQAAAAA3PlRp/yXvrsgK9rbvAEPs; _ga=GA1.2.449421393.1542056499; _gid=GA1.2.2110672116.1542056499; docscrollltop=0; LPVID=FkMTc4MDEwMzY3NDllNjU5; LPSID-34568906=eQOy1bjvTWS3lx1mTF5b3w");
client.Headers.Add("x-requested-with","XMLHttpRequest");
client.Headers.Add("betslip-hash","578c9b9896d955c14a698bf17937400a");
client.Headers.Add("content-type","application/x-www-form-urlencoded; charset=UTF-8");
client.Headers.Add("ajax-json","true");

string jsonOneXBetData = client.DownloadString(url);