• HTTP SOAP Request


    public string SoapRequest(string url, string message, string type, Encoding encoding)
            {
                string result = string.Empty;
                Stream reqstr = null;
                System.IO.Stream responseStream = null;
                System.IO.StreamReader reader = null;
                try
                {
                    HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
                    request.Method = type.ToString();
                    request.ContentType = "application/soap+xml;charset=UTF-8;action="" + url + """;
                    request.Headers.Add("SOAPAction", url);
                    
                    if (type.ToString().ToLower() == "post")
                    {
                        reqstr = request.GetRequestStream();
                        byte[] buff = encoding.GetBytes(message);
                        reqstr.Write(buff, 0, buff.Length);
                        reqstr.Flush();
                        reqstr.Close();
                        reqstr.Dispose();
                        reqstr = null;
                    }
                    // 接收返回的页面
                    HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                    responseStream = response.GetResponseStream();
                    reader = new System.IO.StreamReader(responseStream, encoding);
                    result = reader.ReadToEnd();
                    if (OnStateComplate != null)
                        OnStateComplate(result, fspc);
                    if (OnReplyComplate != null)
                        OnReplyComplate(result, fspc);
                    return result;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    if (reader != null)
                    {
                        reader.Close();
                        reader.Dispose();
                    }
                    if (reqstr != null)
                    {
                        reqstr.Flush();
                        reqstr.Close();
                        reqstr.Dispose();
                    }
                    if (responseStream != null)
                    {
                        responseStream.Flush();
                        responseStream.Close();
                        responseStream.Dispose();
                    }
                }
                
            }
    public static string GetStringSOAP1(Hashtable ht,string target)
            {
                StringBuilder body = new StringBuilder();
                body.Append("<?xml version="1.0" encoding="utf-8"?>");
                body.Append("<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">");
                body.Append("<soap:Body>");
                body.Append("<"+target+" xmlns="http://service.pubinfo.com.cn">");
                body.AppendFormat("<in0>{0}</in0>", ht["loginName"].ToString());
                body.AppendFormat("<in1>{0}</in1>", ht["loginPWD"].ToString());
                int index = 2;
                if (ht.ContainsKey("mobiles") && !string.IsNullOrEmpty(ht["mobiles"].ToString()))
                {
                    body.AppendFormat("<in{1}>{0}</in{1}>", ht["mobiles"].ToString(),index++);
                }
                if (ht.ContainsKey("content") && !string.IsNullOrEmpty(ht["content"].ToString()))
                {
                    body.AppendFormat("<in{1}>{0}</in{1}>", ht["content"].ToString(), index++);
                }
                if (ht.ContainsKey("sendNo")  && !string.IsNullOrEmpty(ht["sendNo"].ToString()))
                {
                    body.AppendFormat("<in{1}>{0}</in{1}>", ht["sendNo"].ToString(), index++);
                }
                body.Append("</"+target+"></soap:Body></soap:Envelope>");
                return body.ToString();
            }
  • 相关阅读:
    Djiango项目的创建以及配置介绍1
    最大矩形土地 单调栈或者DP
    0917 lxs 反思
    0915 反思
    codeforces 1209/C Paint the Digits 观察
    NOIP2014 解方程 秦九韶算法+多项式处理
    整数拆分问题
    机器人M号
    有趣的数列 唯一分解定理+卡特兰数
    数位DP 不要62
  • 原文地址:https://www.cnblogs.com/gxivwshjj/p/4757150.html
Copyright © 2020-2023  润新知