C\#웹 서 비 스 를 호출 하기 위해 HttpPost 요청 을 보 내 는 방법
void UpdateContactSign()
        {
           string ServerPage ="http://localhost/WebService/MyService.asmx";
            try
            {
                //ServerPage += "?op=TangramAction";
                ServerPage += "/MyAction";//MyAction WebService    
           string strXml="<a ObjID=\"9\"></a>",;//     
           string strData="ContactSign|990011|    ";//     
           string res = HttpConnectToServer(ServerPage, strXml, strData);
                //MessageBox.Show(res);
            }
            catch (Exception ex)
            {
            }
        }
        //        
      public string HttpConnectToServer(string ServerPage,string strXml,string strData)
        {
            string postData = "strXml=" + strXml+"&strData="+strData;
            byte[] dataArray = Encoding.Default.GetBytes(postData);
            //    
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(ServerPage);
            request.Method = "POST";
            request.ContentLength = dataArray.Length;
            request.ContentType = "application/x-www-form-urlencoded";
            //     
            Stream dataStream = null;
            try
            {
                dataStream = request.GetRequestStream();
            }
            catch (Exception)
            {
                return null;//       
            }
            //    
            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;//       
            }
            return res;
        }
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Liberty로 웹 서비스 앱 개발 노트 : (1) 환경 구축웹 서비스(REST) 앱을 개발하고 Liberty상에서 움직일 때까지의 흐름에 대해 시도한 것을 비망록으로 기재해 갑니다. 최종적으로는 Eclipse, Liberty, JAX-RS, GitHub, Maven, JUn...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.