简体   繁体   English

覆盖XDocument.Load请求标头

[英]Override XDocument.Load Request Headers

I am currently using Google's Finance API to pull stock information. 我目前正在使用Google的Finance API来提取股票信息。 (Yes I know it is deprecated and may be discontinued soon). (是的我知道它已被弃用,很快就会停止使用)。

When I load the XML: 当我加载XML时:

XDocument doc = XDocument.Load("http://www.google.com/ig/api?stock=ticker");

I am returning a 503 (probably due to to many requests in a given time period. 我将返回503(可能是由于在给定时间段内的许多请求。

Is there anyway I can override the request headers sent to more or less mimic a user agent header from chrome? 无论如何,我可以覆盖发送到或多或少模仿来自chrome的用户代理标头的请求标头?

Is there anyway I can override the request headers sent to more or less mimic a user agent header from chrome? 无论如何,我可以覆盖发送到或多或少模仿来自chrome的用户代理标头的请求标头?

The simplest approach is probably not to use the overload that takes a URL in that case. 最简单的方法可能是不使用在这种情况下采用URL的重载。 Instead, create a WebRequest which has all the headers and any other customizations you want, get the response, and pass the response stream to XDocument.Load(Stream) . 而是创建一个WebRequest ,它包含所需的所有标头和任何其他自定义项,获取响应,并将响应流传递给XDocument.Load(Stream)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM