在 Windows 8 中,我尝试从 URL 获取 html 源代码:
private void loadingDatafromWeb(string URL)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL);
request.BeginGetResponse(new AsyncCallback(ReadCallbackLoadingData),request);
}
和:
private void ReadCallbackLoadingData(IAsyncResult asynchronousResult)
{
string myPageSource;
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
using (StreamReader myWebSource = new StreamReader(response.GetResponseStream()))
{
myPageSource = myWebSource.ReadToEnd();
}
我想在函数 loadingDatafromWeb 中获取字符串 myPageSource,但我做不到。请告诉我怎么做?