A   http://www.hzti.com/government/news.aspx?id=57618
B   http://www.hzti.com/government/ajaxnews.aspx?ID=57618访问a,他的文章内容是通过ajax请求获取的地址是B.可是用curl直接获取B却报一个服务器错误。服务器错误的产生分析:如果访问A之后,访问B,B可以返回一个xml结果如果直接访问B则是一个服务器错误。
分析可能是session ,cookie的原因,但是,添加了session ,cookie还是无法用curl获取正确内容。
请高手帮忙分析原因,也可以提供其它抓取到内容的解决方案。错误信息,
、、、、、、、、、、、/
“/”应用程序中的服务器错误。
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。堆栈跟踪:[NullReferenceException: 未将对象引用设置到对象的实例。]
   service_news_ajaxnews.Page_Load(Object sender, EventArgs e) +90
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
版本信息: Microsoft .NET Framework 版本:2.0.50727.4206; ASP.NET 版本:2.0.50727.4209 
正确结果<?xml version="1.0" ?><news><source></source><createdate>2011/4/6 11:05:46</createdate><title>关于留石快速路古墩路跨线桥维修期间实施临时交通管制的通告</title><count>0</count><content>&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style=&quot;layout-grid-mode: char; text-indent: 21pt&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-size: 12pt&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: 22pt&quot;&gt;关于留石快速路古墩路跨线桥维修期间&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;layout-grid-mode: char; line-height: 25pt&quot; align=&quot;center&quot;&gt;&lt;span style=&quot;font-size: 22pt&quot;&gt;实施临时交通管制的通告&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;layout-grid-mode: char; text-indent: 32pt&quot; align=&quot;left&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;layout-grid-mode: char; text-indent: 32pt; line-height: 30pt&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-size: 16pt&quot;&gt;因留石快速路古墩路跨线桥伸缩缝维修施工需要,为确保交通安全,根据《中华人民共和国道路交通安全法》第三十九条之规定,在维修施工期间,公安交通管理部门将实施临时交通管制措施。现将有关事项通告如下:&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;layout-grid-mode: char; text-indent: 32pt; line-height: 30pt&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-size: 16pt&quot;&gt;自4月 10日起至4月30日止,留石快速路古墩路跨线桥南半幅全封闭施工,机动车由东向西保持现状通行,机动车由西向东通行改走地面道路。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;layout-grid-mode: char; text-indent: 32pt; line-height: 30pt&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-size: 16pt&quot;&gt;请过往机动车依照施工区相关交通标志、标线指示通行,并服从现场民警和管理人员的指挥。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;layout-grid-mode: char; text-indent: 32pt; line-height: 30pt&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-size: 16pt&quot;&gt;特此通告。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;layout-grid-mode: char; line-height: 30pt&quot; align=&quot;right&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;layout-grid-mode: char; word-break: break-all; line-height: 30pt&quot; align=&quot;right&quot;&gt;&lt;span style=&quot;font-size: 16pt&quot;&gt;杭州市公安局交通警察局&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;layout-grid-mode: char; word-break: break-all; line-height: 30pt&quot; align=&quot;right&quot;&gt;&lt;span style=&quot;font-size: 16pt&quot;&gt;二○一一年四月三日&lt;/span&gt;&lt;/div&gt;</content><attach>1169</attach><name>附图.doc</name><loadcount>66</loadcount><canre>0</canre></news>

解决方案 »

  1.   

    curl 很麻烦。一般都不用这个东西~
      

  2.   

    没有设置请求内HEAD头中的Refer,很多判断是否盗链,靠的就是Refer。
      

  3.   

    直接访问能打开的。:http://www.hzti.com/government/ajaxnews.aspx?ID=57618
    那只能证明你代码搞错了
      

  4.   

    用firebug看看请求的头部都有些什么内容模拟抓取,就要cookie和header全部模拟清楚
      

  5.   

    你用Snoopy类试试,google中搜php Snoopy就可以下载到