首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

怎么接收、发送数据

2013-10-12 
如何接收、发送数据?一个系统抛过来的数据,经过加工处理,再抛给另一个系统。如何处理,数据比较通用的格式是

如何接收、发送数据?
一个系统抛过来的数据,经过加工处理,再抛给另一个系统。

如何处理,数据比较通用的格式是什么,最好有这样的案例,谢谢。
[解决办法]

string PingAnResponXml = "";
            HttpWebRequest PingAnRequest = null;
            HttpWebResponse PingAnResponse = null;
            Encoding encodeType = Encoding.GetEncoding("GB2312");
            //连接超时后重新建立连接
            for (int i = 0; i < 2; i++)
            {
                try
                {
                    PingAnResponXml = "";
                    //验证服务器证书回调自动验证
                    MyPolicy myPolicy = new MyPolicy();
                    ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(myPolicy.AcceptAllCertifications);
                    //建立连接
                    PingAnRequest = (HttpWebRequest)WebRequest.Create(Configuration.PingAnServiceUrl);
                    PingAnRequest.ProtocolVersion = HttpVersion.Version10;

                    //获取私钥路径
                    string clientp12path = System.IO.Path.Combine(HttpRuntime.AppDomainAppPath, "App_Data\\EXV_BIS_IFRONT_PCIS_YZJIB_001_STG.pfx");
                    X509Certificate2 cer = new X509Certificate2(clientp12path, "123456", X509KeyStorageFlags.MachineKeySet);
                     PingAnRequest.ClientCertificates.Add(cer);


                    //设置连接超时
                    PingAnRequest.Timeout = 30000;
                    PingAnRequest.KeepAlive = true;

                    PingAnRequest.Headers.Set("Pragma", "no-cache");
                    PingAnRequest.Method = "POST";
                    PingAnRequest.ContentType = "application/x-www-form-urlencoded";

                    //PingAnRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; Maxthon; .NET CLR 1.1.4322); Http STdns";
                    //PingAnRequest.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
                    //PingAnRequest.CookieContainer = new CookieContainer();
                    byte[] Bytes = encodeType.GetBytes(requestXml);

                    PingAnRequest.ContentLength = Bytes.Length;
                    PingAnRequest.AllowAutoRedirect = true;




                    //发送数据
                    using (Stream writer = PingAnRequest.GetRequestStream())
                    {
                        writer.Write(Bytes, 0, Bytes.Length);
                        writer.Close();
                    }
                    //接收数据--超时处理
                    using (Stream receiveStream = PingAnRequest.GetResponse().GetResponseStream())
                    {
                        StreamReader sr = new StreamReader(receiveStream, encodeType);
                        PingAnResponXml = sr.ReadToEnd();
                        sr.Close();
                        receiveStream.Close();
                    }

                    PingAnRequest.Abort();
                    //PingAnResponse.Close();
                    break;
                }
                catch (Exception ex)
                {
                    //记录日志
                    // CommHelper.AddPolicyResponseLog(policy.PolicyID, "Failed", ex.Message, "", string.Format("请求Xml: {0}; 返回Xml: {1}", requestXml, PingAnResponXml), policy.Order.UpdatorName);

                    PingAnRequest.Abort();
                    if (PingAnResponse != null)
                        PingAnResponse.Close();
                    isSuccess = false;
                    //return "交易请求连接失败";
                    Thread.Sleep(3000);
                }
            }


自己参考参考把

热点排行