- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我使用下面的代码打开了对 YouTube 视频的流请求,但它总是返回异常“远程服务器返回错误:NotFound”。然后我尝试使用 Fiddler 来检测问题,我看到 WebClient 自动将 User-Agent 字段设置为 NativeHost,而不是我的 User-Agent,如下所示。
我向 youtube 发送请求的代码:
private static Task<string> HttpGet(string uri)
{
var task = new TaskCompletionSource<string>();
var web = new WebClient();
web.OpenReadCompleted += (sender, args) =>
{
if (args.Cancelled)
task.SetCanceled();
else if (args.Error != null)
task.SetException(args.Error);
else
{
//var bytes = args.Result.ReadToEnd();
byte[] bytes = new byte[] { };
using (MemoryStream memoryStream = new MemoryStream())
{
args.Result.CopyTo(memoryStream);
bytes = memoryStream.ToArray();
task.SetResult(Encoding.UTF8.GetString(bytes, 0, bytes.Length));
}
}
};
web.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)";
web.OpenReadAsync(new Uri(uri));
return task.Task;
}
从 Fiddler 捕获的 header :
CONNECT www.youtube.com:443 HTTP/1.0
User-Agent: NativeHost
Host: www.youtube.com:443
Content-Length: 0
Connection: Keep-Alive
Pragma: no-cache
请给我一些建议。非常感谢
最佳答案
您可以使用此代码
using (WebClient web = new WebClient())
{
web.Headers["User-Agent"] =
"Mozilla/4.0 (Compatible; Windows NT 5.1; MSIE 6.0) " +
"(compatible; MSIE 6.0; Windows NT 5.1; " +
".NET CLR 1.1.4322; .NET CLR 2.0.50727)";
}
关于c# - 如何在 WebClient 中设置 User-Agent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22656049/
功能介绍 agent.exe程序文件是一个类似Windows更新服务(wuauclt.exe,即Windows Update)的程序,它不是Windows系统的一部分。而是第三方软件公司发布的程序
我正在尝试查找 android 应用程序的用户代理。 该应用程序允许应用程序内浏览,所以我认为它必须有一个用于浏览的用户代理。 我怎么知道那是什么?我正在尝试使用该信息来运行该网站的桌面版本,使其看起
考虑以下代码: (let [slave-agent (agent 0) run-slave (fn [_] (println "running slave agent")) run-m
我最近遇到了“多代理计算”这个术语,但我不太明白它是什么。我读过一本关于它的书,但这并没有回答代理是什么的基本问题。 是否有人有指向一些引用的指针,该引用清晰简洁,并且在没有大量废话/营销言论的情况下
我有一个 java 代理,我可以从它调用另一个代理,通过它传递包含 NoteId 的参数,并使用该 NoteId,我能够成功地完成该文档的工作。直到这里一切都清楚了. 关于此的主要问题是,是否可以从当
SQL Server 2012 SP2 CU6 v-5592 我启动 SQL 服务和 SQL 代理服务;都开始OK。然后我在 Windows 2012 Ent(不是 R2)服务器上登录 SSMS,SQ
有一个应用程序我曾经在 Mozilla 中运行,但我决定使用 Chrome。我选择了BlahBlahBlahSafari.gwt.xml (包含 )在 Google/GWT Compile 的帮助下
这与我的第一个问题有关。我更新了所有代码。在我的 bot.js是: require('dotenv').config(); let ver = process.env.DISCORD_BOT; cli
在 OPA 中,很清楚如何查询 condition AND condition : values := { "value1": { "a": "one" }, "value2":
通过 User-Agent header 检测设备是否为 SmartTV 设备的任何常用方法/模式?可能正在搜索 TV 或其他内容? 请告知还有其他值得检测的电视相关平台吗? UPD:根据这个http
这就是我跑步时它返回给我的东西。我试图更新包,但仍然不起作用。我也试过重新安装Julia,这个包在重新安装后只会运行一次。然后我第二次跑步的时候。它将再次失败。我试着修复它已经很长时间了。。有人能帮我
我是 OPA(开放策略代理)的新手,正在尝试使用 REST API/v1/policies/{id} 创建新策略。有用!但是,OPA 服务器将其保存到内存中,并且在重新启动后我的所有策略都被删除了。我
我想在 K8sPSPCapabilities 约束模板中将一个容器列入白名单,但我在使用 rego 语言时遇到了一些困难。我想禁止除特定容器之外的所有容器的 NET_RAW 功能。如果有人能指出我正确
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
导入命令: “从rasa_core.agent导入代理” 给我以下错误 ----------------------------------------------------------------
我正在为 Eclipse Kepler 开发一个插件。将 @RunWith(JMockit.class) 添加到我的测试类会导致以下错误: JMockit: Reinitializing un
如何使用TD-AGENT-BIT将日志文件作为消息输出,可以是逐行输出,也可以是以“hh:mm:ss”开头的行输出,然后向下游发送,而不是每次一起输出多行日志?日志:。。。我想要下面这样的消息:。。。
我在 SQL Server 上有一个非常奇怪的情况,我无法理解。 环境:SQL Server 2012 SP3 CU3 在 2 节点 Windows 2008 R2 集群上运行 在 SQL Serve
有关该主题的所有其他问题都没有解决我的问题。 注入(inject)器: VirtualMachine vm = VirtualMachine.attach(pid); vm.loadAgent(new
[SSH]“无法打开与您的身份验证代理的连接”。错误 我正在尝试将 ssh key 添加到我的 ssh 代理中。我首先确保 ssh-agent 正在运行。 exec ssh-agent bash 我确
我是一名优秀的程序员,十分优秀!