如何通过HttpWebRequest发送小写的Keep-Alive头 [英] How to send lower-case Keep-Alive header through HttpWebRequest

查看:147
本文介绍了如何通过HttpWebRequest发送小写的Keep-Alive头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个机器人,它应该尽可能地模拟firefox。
通过检查它发送的标题,我发现了一个小的区别,我不知道如何摆脱:

I'm writing a bot, which should emulate firefox as closely as possible. By examining the headers that it is sending, I've found one minor difference, that I do not know how to get rid off:

Firefox使用以下keep-alive header:

Firefox uses following keep-alive header:

Connection: keep-alive

虽然c#总是发出:

Connection: Keep-Alive

我知道这可能没关系,但我仍然想知道是否有任何方法/ hack将该标题修改为全部小写。

I know that it probably does not matter, but I'd still love to know if there is any way/hack to modify that header to be all lower case.

任何想法如何做到这一点?

Any ideas how to do this?

推荐答案

在.net 4.0中,这有效:

In .net 4.0 this works:

request.Headers.GetType().InvokeMember(
    "ChangeInternal",
    BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod,
    Type.DefaultBinder, 
    request.Headers, 
    new object[] { "Connection", "keep-alive" }
);

请确保您没有在请求中实际设置KeepAlive属性

Just be sure you don't actually set the KeepAlive property on the request

这篇关于如何通过HttpWebRequest发送小写的Keep-Alive头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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