• 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();
            }
  • 相关阅读:
    ehcache 详解 实例
    oscache ehcache oscache与ehcache的区别
    Nginx_lua
    Java程序员的发展前景
    JAVA MemCache 史无前例的详细讲解!看完包精通MEMCACHE!
    java ssl https 连接详解 生成证书
    使用django的ImageField和from制作上传图片页面
    1.python中的列表及其操作
    django分页
    django和javaweb的比较
  • 原文地址:https://www.cnblogs.com/gxivwshjj/p/4757150.html
Copyright © 2020-2023  润新知