猿问

学习编程问题,怎么觉得微软官网上有错

今天学习要用到这个类HttpWebRequest,在msdn上查找  在这个网页上http://msdn.microsoft.com/zh-cn/library/system.net.httpwebrequest_members(v=vs.90).aspx

但是我就觉得很郁闷,我在我的vs里建立了HttpWebRequest类就是点不出GetResponse方法。

然后我又到这个网页http://msdn.microsoft.com/zh-cn/library/system.net.httpwebrequest.getresponse(v=vs.90).aspx复制粘贴下面的代码都有错编译不过去。

HttpWebRequest request = (HttpWebRequest)WebRequest.Create (args[0]);

// Set some reasonable limits on resources used by this request
request.MaximumAutomaticRedirections = 4;
request.MaximumResponseHeadersLength = 4;
// Set credentials to use for this request.
request.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse response = (HttpWebResponse)request.GetResponse ();

Console.WriteLine ("Content length is {0}", response.ContentLength);
Console.WriteLine ("Content type is {0}", response.ContentType);

// Get the stream associated with the response.
Stream receiveStream = response.GetResponseStream ();

// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader (receiveStream, Encoding.UTF8);

Console.WriteLine ("Response stream received.");
Console.WriteLine (readStream.ReadToEnd ());
response.Close ();
readStream.Close ();



这是怎么回事?求解?

慕勒3428872
浏览 382回答 4
4回答

九州编程

说了这么大堆你漏掉了最重要的一点就是开发环境,windows phone开发中不支持同步的操作,所有网络操作必须是异步的。你只能用BeginGetResponse。继续去看例子吧。

一只名叫tom的猫

我前面就试了,不是版本的问题。
随时随地看视频慕课网APP
我要回答