应该用到哪些类?Socket?给我个大框架吧,不知道从哪写起,怎么站外url post数据,哪些类负责发接,回调什么的,谢谢啦

解决方案 »

  1.   

    还有一问题 Dns.BeginResolve 说过时了,这个是怎么回事,有代替的东西么?
      

  2.   

    你url是一个网站的话。使用:httpResponse就可以。 public static string GetHtml(string url, string postData, Encoding enc)
            {
                string result = "";
                try
                {
                    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url + "&" + postData);
                    req.Method = "GET";
                    req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; Maxthon; .NET CLR 1.1.4322; .NET CLR 2.0.50727; Alexa Toolbar)";
                    req.ContentType = "application/x-www-form-urlencoded";                HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
                    StreamReader sr = new StreamReader(resp.GetResponseStream(), enc);
                    result = sr.ReadToEnd();
                    sr.Close();
                    resp.Close();
                }
                catch (Exception)
                {
                    result = "";
                }
                return result;
            }        public static string PostHtml(string url, string postData, Encoding enc)
            {
                string result = "";
                try
                {
                    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url + "&" + postData);
                    req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; Maxthon; .NET CLR 1.1.4322; .NET CLR 2.0.50727; Alexa Toolbar)";
                    req.ContentType = "application/x-www-form-urlencoded";
                    HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
                    StreamReader sr = new StreamReader(resp.GetResponseStream(), enc);
                    result = sr.ReadToEnd();
                    sr.Close();
                    resp.Close();
                }
                catch (Exception)
                {
                    result = "";
                }
                return result;
            }
    //调用
    StrData = PubVar.PostHtml(StrData, StrPost, Encoding.Default);            if (StrData == "") return CreateXmlDocument("Query Error");
      

  3.   

    Thread threadpostdata = new Thread(PostData);
    threadpostdata.Start();
    void PostData()
    {}
      

  4.   


    我后来这样写了,不知道对不对private static ManualResetEvent allDone = new ManualResetEvent(false);        public static void SendPredict(string content)
            {
                System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(Predict), content);
            }        private static void Predict(object content)
            {
                byte[] data = Encoding.UTF8.GetBytes(PostParam(content.ToString()));            HttpWebRequest request = WebRequest.Create("http://guba.hexun.com/CallBack.aspx") as HttpWebRequest;
                request.ContentType = "application/x-www-form-urlencoded";
                request.Method = "POST";
                request.Timeout = 100000;
                request.ContentLength = data.Length;
                            Stream stream = request.GetRequestStream();
                stream.Write(data, 0, data.Length);
                stream.Close();
                request.BeginGetResponse(new AsyncCallback(PredictCallback), request);            allDone.WaitOne();
            }        private static void PredictCallback(IAsyncResult asynchronousResult)
            {
                try
                {
                    HttpWebRequest request = asynchronousResult.AsyncState as HttpWebRequest;                HttpWebResponse response = request.EndGetResponse(asynchronousResult) as HttpWebResponse;
                    Stream streamResponse = response.GetResponseStream();
                    StreamReader streamRead = new StreamReader(streamResponse, Encoding.Default);
                    string content = streamRead.ReadToEnd();                streamResponse.Close();
                    streamRead.Close();
                    response.Close();
                    allDone.Set();
                }
                catch (Exception e)
                {
                    string error = e.ToString();                
                }
            }