最近写个程序,在不通过路由,直连宽带情况下,HTTP GET请求会抛出异常,提示远程服务器无响应,POST上传流数据可以请求到,但是第一次很慢,请求过一次就快了,GET请求也好了,实在是诡异。服务器为Tomcat9,客户端请求代码如下
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(host+"/Yiyun/Api?method=getProxyIp");
string result = "";
try
{
//请求头
req.Accept = "text/html, application/xhtml+xml, */*";
req.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko";
req.ContentType = "multipart/form-data";
req.Connection = "KeepAlive";
req.Timeout = 10000;
req.Method = "POST";
HttpWebResponse wr = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(wr.GetResponseStream());
result = sr.ReadToEnd();
sr.Close();
wr.Close();
ipList.AddRange(result.Split(','));
}
catch (Exception e)
{
}