How to send lower-case Keep-Alive header through HttpWebRequest

前端 未结 3 1565
刺人心
刺人心 2020-12-16 08:09

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 ho

3条回答
  •  孤街浪徒
    2020-12-16 08:44

    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" }
    );
    

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

提交回复
热议问题