Override Host in HttpClient

柔情痞子 提交于 2019-12-08 05:43:47

问题


I'm using HttpClient but it has problems with DNS resolve (it is using the sync method for this) So I use another lib for doing DNS queries and now I'm tryging to get custom urls by IP but I need to replace Host header. For example I have url http://fb.com but I need to get http://1.1.1.1 with Host set to fb.com I've tryied:

_req = new HttpRequestMessage(HttpMethod.Get, newUri.ToString());
_req.Headers.Host = uri.Host;
_httpClient.DefaultRequestHeaders.Host = uri.Host;

but this doesn't work. Is there any way to set own Host header like in HttpWebRequest?


回答1:


It's work. The problem was with Fiddler which override Host header based on url. When Fiddler is off everything is going fine.



来源:https://stackoverflow.com/questions/35303372/override-host-in-httpclient

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!