我希望构建一个 HTTPPing 实用程序,它可以绕过我们的负载均衡器并测试我们的 SharePoint 环境中的每个前端。编写(或查找)HTTPPing 并不困难,只是让它在我们的环境中运行。
我们的 SharePoint 环境中有五个 Web 应用程序,它们在负载平衡器后面运行,该负载平衡器在 10 个前端之间进行平衡。五个 Web 应用程序中的每一个都通过映射到虚拟 IP 的 DNS 条目进行访问,因此:
webapp1.mycompany.com --> 10.20.30.10
webapp2.mycompany.com --> 10.20.30.11
webapp3.mycompany.com --> 10.20.30.12
webapp4.mycompany.com --> 10.20.30.13
webapp5.mycompany.com --> 10.20.30.14
前端机器的IP地址可能是:
Front End 1 --> 10.22.33.40
Front End 2 --> 10.22.33.41
...
Front End 10 --> 10.22.33.49
我们的 SharePoint 环境使用备用访问映射,所以我不能做 http://10.22.33.40/ , 但有使用 http://webapp1.mycompany.com
如果我更改我的主机文件以包含条目,我可以直接访问一台机器:
webapp1.mycompany.com --> 10.22.33.40
但是 5 个 Web 应用程序 x 10 个前端意味着 50 个更改,我认为有更好的方法可以做到这一点。我希望该程序不编辑主机文件。
谢谢,蒂姆
最佳答案
您可以使用反射来欺骗主机 header :
WebRequest wr = WebRequest.Create(@"http://127.0.0.1/Test.html");
wr.Headers.GetType().InvokeMember("ChangeInternal", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null, wr.Headers, new object[] { "Host", "www.example.com" });
var resp = wr.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream());
MessageBox.Show(sr.ReadToEnd().ToString());
归功于 L.B.他的回答。
关于c# - 构建可以覆盖主机文件的 HTTPPing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9161575/