关于httpwebrequest报废的紧急帮助 [英] Urgent help on httpwebrequest scrapping

查看:105
本文介绍了关于httpwebrequest报废的紧急帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

帮助我抓取网站,在asp.net c#中打乱网站,

i我无法获取数据而我正在尝试废弃网站



HttpWebRequest newRequest;



newRequest =(HttpWebRequest)WebRequest.Create(http://flights.makemytrip.com/makemytrip/search/O/O/ E / 1/0/0 / S / V0 / DEL_BOM_14-08-2015?intid = homepage_Widget_Search_New-Delhi_Mumbai);

newRequest.Method = WebRequestMethods.Http.Get;

newRequest.ContentType =text / html; charset = ISO-8859-1; application / json;



newRequest.UserAgent =Mozilla / 5.0(Windows NT 6.1; WOW64; rv:36.0)Gecko / 20100101 Firefox / 36.0;

newRequest.Referer = finalUrlRef;

response =(HttpWebResponse)newRequest.GetResponse();

string readerNewRequest = new StreamReader(response.GetResponseStream())。ReadToEnd();

help me to crawl website ,scarpping website in asp.net c#,
i am unable to get data while i am trying to scrap website

HttpWebRequest newRequest ;

newRequest = (HttpWebRequest)WebRequest.Create("http://flights.makemytrip.com/makemytrip/search/O/O/E/1/0/0/S/V0/DEL_BOM_14-08-2015?intid=homepage_Widget_Search_New-Delhi_Mumbai");
newRequest.Method = WebRequestMethods.Http.Get;
newRequest.ContentType = "text/html;charset=ISO-8859-1;application/json";

newRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0";
newRequest.Referer = finalUrlRef;
response = (HttpWebResponse)newRequest.GetResponse();
string readerNewRequest = new StreamReader(response.GetResponseStream()).ReadToEnd();

推荐答案

查看(或再看) C ode样本做同样的事情: https:// msdn .microsoft.com / zh-CN / library / system.net.webrequest%28v = vs.110%29.aspx



查找10条差异。 :-)



或者,看看我对这个问题的评论。为什么application / json?您没有发送任何JSON,您根本不发送任何内容。也许你混淆了这种内容类型和预期的 HttpWebResponse 的内容类型,但为什么呢?这没有道理。如果需要,请使用 response.ContentType

https://msdn.microsoft.com/en-us/library/system.net.httpwebresponse.contenttype(v = vs.110) .aspx

https://msdn.microsoft.com/en-us/library/system.net.httpwebresponse%28v=vs.110%29.aspx



-SA
Look (or look again) at the code sample doing the same thing: https://msdn.microsoft.com/en-us/library/system.net.webrequest%28v=vs.110%29.aspx.

Find 10 differences. :-)

Or, look at my comment to the question. Why "application/json"? You are not sending any JSON, you are not sending any content at all. Maybe you mix up this content type and content type of expected HttpWebResponse, but why? It makes no sense. If you need that, use response.ContentType:
https://msdn.microsoft.com/en-us/library/system.net.httpwebresponse.contenttype(v=vs.110).aspx,
https://msdn.microsoft.com/en-us/library/system.net.httpwebresponse%28v=vs.110%29.aspx.

—SA


这篇关于关于httpwebrequest报废的紧急帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆