我正在点击一个网址作为以下示例:
http://mobile.example.com/ip/someProduct-fl-oz/productID
我的要求是:
public static string getMobileHtml(string url)
{
string responseData = "";
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Accept = "text/html, application/xhtml+xml, */*";
request.KeepAlive = true;
request.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)";
request.Timeout = 10000;
request.Host = "mobile.example.com";
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
Stream responseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(responseStream);
responseData = myStreamReader.ReadToEnd();
}
response.Close();
}
catch (Exception e)
{
responseData = "An error occurred: " + e.Message;
}
return responseData;
}
并且代码在线崩溃:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
没有任何例外,只是中断了,同样的事情发生了Curl Lib
,WebClient
但我把它改成HttpWebRequest
假设它会是一个修复。有什么建议么?