亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C#發(fā)送HttpPost請求來調(diào)用WebService的方法

 更新時間:2013年03月07日 11:18:51   作者:  
在C#中發(fā)送HttpPost請求來調(diào)用WebService中的MyAction方法,代碼如下:需要的朋友可以參考一下

復(fù)制代碼 代碼如下:

void UpdateContactSign()
        {
           string ServerPage ="http://localhost/WebService/MyService.asmx";
            try
            {
                //ServerPage += "?op=TangramAction";
                ServerPage += "/MyAction";//MyAction是WebService中的方法
           string strXml="<a ObjID=\"9\"></a>",;//第一個參數(shù)
           string strData="ContactSign|990011|我的數(shù)據(jù)";//第二個參數(shù)
           string res = HttpConnectToServer(ServerPage, strXml, strData);
                //MessageBox.Show(res);
            }
            catch (Exception ex)
            {

            }
        }

        //發(fā)送消息到服務(wù)器
      public string HttpConnectToServer(string ServerPage,string strXml,string strData)
        {
            string postData = "strXml=" + strXml+"&strData="+strData;

            byte[] dataArray = Encoding.Default.GetBytes(postData);
            //創(chuàng)建請求
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(ServerPage);
            request.Method = "POST";
            request.ContentLength = dataArray.Length;
            request.ContentType = "application/x-www-form-urlencoded";
            //創(chuàng)建輸入流
            Stream dataStream = null;
            try
            {
                dataStream = request.GetRequestStream();
            }
            catch (Exception)
            {
                return null;//連接服務(wù)器失敗
            }

            //發(fā)送請求
            dataStream.Write(dataArray, 0, dataArray.Length);
            dataStream.Close();
            //讀取返回消息
            string res = string.Empty;
            try
            {
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                res = reader.ReadToEnd();
                reader.Close();
            }
            catch (Exception ex)
            {
                return null;//連接服務(wù)器失敗
            }
            return res;
        }

相關(guān)文章

最新評論