这个代码哪里有问题吗?请求后一直无反应,也不会报超时,但是抓包软件已经看到正常请求和返回了?是不是 HOST 和请求 URI 不一直的问题》??
var handler = new HttpClientHandler
{
AllowAutoRedirect = false,
CookieContainer = new CookieContainer(),
UseCookies = true,
UseProxy = true,
Proxy = new WebProxy("http://127.0.0.1:8888", false),
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; },
MaxAutomaticRedirections = 1,
};
using HttpClient webclient = new(handler);
webclient.DefaultRequestVersion = HttpVersion.Version20;
webclient.Timeout = TimeSpan.FromSeconds(10);
webclient.DefaultRequestHeaders.Host = urls[1];
webclient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", ua(mobile));
webclient.DefaultRequestHeaders.TryAddWithoutValidation("x-requested-with", "com.ct.client");
webclient.DefaultRequestHeaders.TryAddWithoutValidation("upgrade-insecure-requests", "1");
HttpResponseMessage response = await webclient.GetAsync(urls[0]);
然后就一直没反应了
1
zhzhwcn 324 天前
HttpResponseMessage response = await webclient.GetAsync(urls[0]).ConfigureAwait(false);
试试 |