我做的是一个C#的winfom程序,需要请求另一个asp.net的做的网页,并从获取那个页面的返回值。
别的能实现的方法也可以

解决方案 »

  1.   

    HttpWebRequest wr = (HttpWebRequest)HttpWebRequest.Create(Url);
                wr.ContentType = "application/x-www-form-urlencoded";
                wr.Accept = "*/*";
                wr.Referer = Referer; //add your referer
                wr.CookieContainer = new CookieContainer();
                wr.CookieContainer.SetCookies(wr.RequestUri, cookie); //add your cookie
                wr.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)";
                HttpWebResponse myHttpWebResponse = (HttpWebResponse)wr.GetResponse();
                StreamReader oStream = new StreamReader(myHttpWebResponse.GetResponseStream(), System.Text.Encoding.xxx);////add webpage encode
                
                return oStream.ReadToEnd();当然你也可以修改上面程序以达到post方法或者加代理或者自动跳转什么的细节方面的功能
      

  2.   

    HttpWebRequest 
    using System;
    using System.Net;
    using System.Text;
    using System.IO;
        public class Test
        {
            // Specify the URL to receive the request.
            public static void Main (string[] args)
            {
                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 ();
            }
        }/*
    The output from this example will vary depending on the value passed into Main 
    but will be similar to the following:Content length is 1542
    Content type is text/html; charset=utf-8
    Response stream received.
    <html>
    ...
    </html>*/另,啥叫网页的返回值?