让一串字符串参数要通过 对方给你的地址 使用POST方式传递到对方那里,然后对方会返回给你XML内容,然后需要从这个XML中获取相关节点的值。整个过程对我而言相当难。因为以前从来没用过、 有没人发个参考,或者代码示例、

解决方案 »

  1.   

    自己研究吧:
    http://msdn.microsoft.com/en-us/library/debx8sh9.aspx
      

  2.   

    调用web services返回XML内容
      

  3.   

    /// <summary>
            /// Get Content of one page by Post Mothod
            /// </summary>
            /// <param name="url">address of page</param>
            /// <param name="encoding">encode or charset</param>
            /// <returns>the content of page</returns>
            public static string Post(string url, string accept, string contentType, string referer, string language,string postContent, CookieContainer cc, Encoding encoding, out string returnUrl) {
                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
                req.CookieContainer = cc;
                req.Accept = accept;
                req.ContentType = contentType;
                req.Referer = referer;
                req.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; InfoPath.2; .NET CLR 3.0.04506; .NET CLR 3.5.21022)";
                if (!string.IsNullOrEmpty(language)) {
                    req.Headers.Add("Accept-Language", language);
                }
                req.Headers.Add("UA-CPU", "x86");
                req.AllowAutoRedirect = true;
                req.UseDefaultCredentials = true;
                req.Method = "POST";            if (!string.IsNullOrEmpty(postContent)) {
                   using(StreamWriter sw = new StreamWriter(req.GetRequestStream(),encoding)){
                       sw.Write(postContent);
                       sw.Flush();
                   }
                }
                using (HttpWebResponse res = (HttpWebResponse)req.GetResponse())
                {
                    Stream response = res.GetResponseStream();
                    if (req.CookieContainer != null) {
                        res.Cookies = req.CookieContainer.GetCookies(req.RequestUri);                   
                    }
                    string responseUrl = res.ResponseUri.ToString();
                    returnUrl = responseUrl;
                    using (StreamReader sr = new StreamReader(response, encoding)) {
                        string content = sr.ReadToEnd();
                        Debug.WriteLine("GetHtml of url:" + returnUrl);
                        Debug.WriteLine(content);
                        return content;
                    }
                }
            }
    关键是理解这个过程,才能写出万变的代码,以上仅供参考。
      

  4.   

    假设参数是NumID=123 他给定的地址是http://www.ddd.dll通过程序应该POST的完整URL就是“http://www.ddd.dll?NumID=123”
    对方会返回以下格式的内容
    <?xml version="1.0" encoding="gb2312" ?> 
      <ActionResult>
      <xMsgID>309</xMsgID> 
      <xCode>1012</xCode> 
      <xMessage>参数错误</xMessage> 
      <xSign>245f5ffdbb0321bf2b682b5e404d894e</xSign> 
      <xValue>0</xValue> 
      </ActionResult>
    然后取出关键的几个节点的值。就是这整个过程如何使用代码描述下来。