我这个代码 用 VS 测试的话 是可以 获得 百度的页面的,但是放到虚拟机上,或者 我的虚拟空间里面就不行了?
不知道是何原因啊
我引入了 MSXML2.XMLHTTP 这个Com
传入网站空间之后 总是 提示 _xmlhttp.send(""); 这行有错误?
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string pageHTML = GetRemoteHtmlCode("http://www.baidu.com/");
Response.Write(pageHTML);
}
public string GetRemoteHtmlCode(string Url)
{
string strOut = string.Empty;
MSXML2.XMLHTTP _xmlhttp = new MSXML2.XMLHTTPClass();
_xmlhttp.open("GET", Url, false, null, null);
_xmlhttp.send("");
if (_xmlhttp.readyState == 4)
{
strOut = System.Text.Encoding.Default.GetString((byte[])_xmlhttp.responseBody);
}
if (strOut.Contains("charset=utf-8") || strOut.Contains("charset=UTF-8"))
{
strOut = ConvertCode(strOut, "utf-8", "gb2312");
}
return strOut;
}
public String ConvertCode(string htmlOrString, string srcEncoding, string dstEncoding)
{
String strOut = null;
System.Text.Encoding oldEncoding = null;
if (srcEncoding.ToLower() == "utf-8")
{
oldEncoding = System.Text.Encoding.UTF8;
}
if (srcEncoding.ToLower() == "utf-32")
{
oldEncoding = System.Text.Encoding.UTF32;
}
System.Text.Encoding newEncoding = System.Text.Encoding.GetEncoding(dstEncoding);
strOut = newEncoding.GetString(System.Text.Encoding.Convert(oldEncoding, newEncoding, newEncoding.GetBytes(htmlOrString)));
return strOut;
}
}
把GET改成POST试试