今天学习要用到这个类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 ();
这是怎么回事?求解?
- 4 回答
- 0 关注
- 381 浏览
添加回答
举报
0/150
提交
取消