URL에 따라 웹 출력 데이터 읽기

5884 단어 url
웹 페이지의 Reponse 데이터를 읽습니다. 다음은 물결치는 문자의 실례입니다.
 public static string HttpSMSPost(HttpWebRequest hr, string url, string parameters)

         {

            string strRet = null;

            ASCIIEncoding encoding = new ASCIIEncoding(); 

            byte[] data = encoding.GetBytes(parameters); 



            try

            {

                hr.KeepAlive = false;

                hr.Method = "POST";

                hr.ContentType = "application/x-www-form-urlencoded";

                hr.ContentLength = data.Length; 

                Stream newStream = hr.GetRequestStream();

                newStream.Write(data, 0, data.Length);

                newStream.Close();



                HttpWebResponse myResponse = (HttpWebResponse)hr.GetResponse();    

                StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.Default);

                strRet = reader.ReadToEnd();      

                reader.Close();

                myResponse.Close();



                return strRet;

        

            }

            catch (Exception ex)

            {

                strRet = "-200";

            }

            return strRet;

        }

사용:
        string url = http://test.com/Login.asp;

        string SMSparameters = "UserID=" + Userid + "&Account=" + Account + "&Password=" + PassWord;



        string targeturl = url.Trim().ToString();

        HttpWebRequest hr = (HttpWebRequest)WebRequest.Create(targeturl);

        hr.CookieContainer = cookieContainerSMS;

        string res = httpPost.HttpSMSPost(hr, url, SMSparameters);



        XmlDocument xml = new XmlDocument();

        xml.LoadXml(res);

        string errorNum = xml.SelectSingleNode("/LANZ_ROOT/ErrorNum").InnerText;  // 



        ActiveID = xml.SelectSingleNode("/LANZ_ROOT/ActiveID").InnerText;  // ActiveID 

        if (errorNum == "0")

        {

            //this.Close();

            Response.Write(" ");

        }

        else

        {

            Response.Write("<script>alert(' ')</script>");

            //this.Close();

        }

좋은 웹페이지 즐겨찾기