string Path = ” ";
// Creates an HttpWebRequest with the specified URL.
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(Path);
// Sends the HttpWebRequest and waits for the response.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
// Gets the stream associated with the response.
Stream receiveStream = myHttpWebResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader sr = new StreamReader(receiveStream, encode);
string rl;
StringBuilder sb = new StringBuilder();
while ((rl = sr.ReadLine()) != null)
{
sb.Append(rl);
}
string stra = sb.ToString();
try
{
//Get XML
int IndexofA = stra.IndexOf("<?xml version=\"1.0\" encoding=\"utf-16\"?>");
int IndexofB = stra.IndexOf("</span>");
string Ru = stra.Substring(IndexofA, IndexofB - IndexofA);
//Replace localhost
lblMess.Text = Ru.ToString();
}
catch
{
lblMess.Text = "无法查询!";
}